自己用java做了一個類似紅蜻蜓截圖的軟件,里面要制作文件命名的模板,
如:

#aa##bb###
#為需要用指定序號替換的字符,10起始值
連續#個數小于等于起始值位數,#被起始值直接替換
連續#個數大于起始值位數時,#被起始值替換并且多出的#用0替換
如:
#aa##bb###
#為需要用指定序號替換的字符,10起始值
連續#個數小于等于起始值位數,#被起始值直接替換
連續#個數大于起始值位數時,#被起始值替換并且多出的#用0替換
1
import java.util.regex.Matcher;
2
import java.util.regex.Pattern;
3
4
5
public class Test {
6
7
public static void main(String[] args) {
8
String template = "#a##b###c";
9
String show1 = null, show2 = null, show3 = null;
10
int start = 10;
11
String startStr = String.valueOf(start);
12
13
String regex = "#{1,}";
14
String[] splitStr = template.split(regex);
15
if (template.indexOf("#") == -1) {
16
show1 = template + start;
17
show2 = template + (start + 1);
18
show3 = template + (start + 2);
19
} else {
20
if (splitStr.length == 0) {
21
if (String.valueOf(start).length() >= template.length())
22
show1 = String.valueOf(start);
23
else {
24
String s = template.substring(0, template.length()
25
- String.valueOf(start).length());
26
show1 = (s + start).replace("#", "0");
27
}
28
if (String.valueOf(start + 1).length() >= template.length()) {
29
show2 = String.valueOf(start + 1);
30
} else {
31
String s = template.substring(0, template.length()
32
- String.valueOf(start + 1).length());
33
show2 = (s + (start + 1)).replace("#", "0");
34
}
35
if (String.valueOf(start + 2).length() >= template.length()) {
36
show3 = String.valueOf(start + 2);
37
} else {
38
String s = template.substring(0, template.length()
39
- String.valueOf(start + 2).length());
40
show3 = (s + (start + 2)).replace("#", "0");
41
}
42
} else {
43
Pattern pattern = Pattern.compile(regex);
44
Matcher match = pattern.matcher(template);
45
46
StringBuffer buffer1 = new StringBuffer();
47
StringBuffer buffer2 = new StringBuffer();
48
StringBuffer buffer3 = new StringBuffer();
49
50
int index = 0;
51
while (match.find()) {
52
String rules = match.group();
53
buffer1.append(splitStr[index]);
54
buffer2.append(splitStr[index]);
55
buffer3.append(splitStr[index]);
56
57
if (rules.length() <= String.valueOf(start).length()) {
58
buffer1.append(start);
59
} else {
60
String s = rules.substring(0, rules.length()
61
- startStr.length());
62
63
buffer1.append((s + start).replace("#", "0"));
64
}
65
if (rules.length() <= String.valueOf(start + 1).length()) {
66
buffer2.append(start + 1);
67
} else {
68
String s = rules.substring(0, rules.length()
69
- String.valueOf(start + 1).length());
70
String tmp2 = (s + (start + 1)).replace("#", "0");
71
72
buffer2.append(tmp2);
73
}
74
if (rules.length() <= String.valueOf(start + 2).length()) {
75
buffer3.append(start + 2);
76
} else {
77
String s = rules.substring(0, rules.length()
78
- String.valueOf(start + 1).length());
79
String tmp3 = (s + (start + 2)).replace("#", "0");
80
81
buffer3.append(tmp3);
82
}
83
index++;
84
}
85
if (index < splitStr.length) {
86
buffer1.append(splitStr[index]);
87
buffer2.append(splitStr[index]);
88
buffer3.append(splitStr[index]);
89
}
90
show1 = buffer1.toString();
91
show2 = buffer2.toString();
92
show3 = buffer3.toString();
93
}
94
}
95
System.out.println("show1: "+show1);
96
System.out.println("show2: "+show2);
97
System.out.println("show3: "+show3);
98
}
99
}
100

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100
