在一个长字符串中查找"包含所要求多个字符串的最短字符串"的VBscript算法
1
<%
2
function GetPos(start,word)
3
dim i,IntIndex,MaxIndex
4
dim flag
5
flag = 1
6
MaxIndex = 0
7
for i=0 to ubound(ArrWord)
8
if i<>cint(word) then
9
IntIndex = Instr(start+len(ArrWord(word)),StrObj,ArrWord(i))
10
if IntIndex>0 then
11
flag = flag + 1
12
'response.write flag & ":" & i & "<br>"
13
if MaxIndex<(IntIndex+len(ArrWord(i))) then
14
MaxIndex = IntIndex+len(ArrWord(i))
15
end if
16
end if
17
end if
18
next
19
if flag = ubound(ArrWord)+1 then
20
GetPos = "(" & start & "," & cstr(MaxIndex-start) & ")"
21
else
22
GetPos = "(1,2,3)"
23
end if
24
25
end function
26
27
function GetNearest()
28
dim i,StrResult,IntIndex,Seq,StrResult1
29
StrResult = ","
30
StrResult1 = ","
31
for i = 0 to ubound(ArrWord)
32
Seq = 1
33
IntIndex = Instr(Seq,StrObj,ArrWord(i))
34
do until IntIndex<1
35
StrResult = StrResult & IntIndex & ","
36
StrResult1 = StrResult1 & i & ","
37
Seq = IntIndex + Len(ArrWord(i))
38
IntIndex = Instr(Seq,StrObj,ArrWord(i))
39
loop
40
next
41
StrResult = left(StrResult,len(StrResult)-1)
42
StrResult = right(StrResult,len(StrResult)-1)
43
StrResult1 = left(StrResult1,len(StrResult1)-1)
44
StrResult1 = right(StrResult1,len(StrResult1)-1)
45
GetNearest = StrResult & "|" & StrResult1
46
end function
47
48
dim StrObj,ArrWord,ArrDotList,ArrWordList,ArrAll,i,ArrLen,StrLenList
49
'StrObj="wer张三色单峰驼retert李四李四李四sdf张三色单峰驼rete34王五53赵六543543rt李四sdfwe"
50
StrObj="aaa张三bbbb李四李四李四ccc张三dddddddd王五e赵六f李四ggg王五热土hhhhhhh赵六"
51
ArrWord = Array("张三","李四","王五","赵六","刘七")
52
ArrAll = split(GetNearest,"|")
53
ArrDotList = split(ArrAll(0),",")
54
ArrWordList = split(ArrAll(1),",")
55
StrLenList = ""
56
57
for i=0 to ubound(ArrDotList)
58
StrLenList = StrLenList & GetPos(ArrDotList(i),ArrWordList(i))
59
next
60
'response.write StrLenList & "<br>"
61
StrLenList = left(StrLenList,len(StrLenList)-1)
62
StrLenList = right(StrLenList,len(StrLenList)-1)
63
64
ArrLen = split(StrLenList,")(")
65
66
dim MinMarginId,MinMargin,ArrTemp,MinMarginStart
67
MinMargin = 100000
68
for i=0 to ubound(ArrLen)
69
ArrTemp = split(ArrLen(i),",")
70
if ubound(ArrTemp)<2 then
71
if cint(ArrTemp(1))<MinMargin then
72
MinMargin = cint(ArrTemp(1))
73
MinMarginStart = cint(ArrTemp(0))
74
MinMarginId = i
75
end if
76
end if
77
next
78
79
if MinMargin<>100000 then
80
response.write "包含所要求多个字符串的最短字符串为:" & mid(StrObj,MinMarginStart,MinMargin)
81
else
82
response.write "包含所要求多个字符串的最短字符串为:制定的某字符串在整个字符串中不存在"
83
end if
84
85
86
87
%>
88

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

分类:
Classic ASP
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架