在两个值之间读取

时间:2015-09-29 20:00:44

标签: vbscript

在询问用户是否想要介于两者之间时,我必须读取两个值。

如果用户在文本

中选择1,则为例
'Hi' My name is 'Kev'in and i'm happ'y' to be 'there'

他将

'Hi' 'Kev' 'y' 'there'

在文本文件中。如果他选择2,他将会

My name is in and i'm happ to be

现在我正在使用

Do While objScriptFile.AtEndOfStream <> True
   strCurrentLine = objScriptFile.ReadLine
     intIsComment = InStr(1,strCurrentLine,"'")
   If intIsComment > 0 Then
     objCommentFile.Write strCurrentLine & vbCrLf
   End If
Loop
Else  

现在它只读取两个值(介于'和之间)但我不知道如何更改它。

1 个答案:

答案 0 :(得分:1)

如果分隔符是唯一的,那很简单。将行分开'并输出偶数或奇数数组元素,具体取决于是选择1还是2。

...
strCurrentLine = "'Hi' My name is 'Kev'in and i`m happ'y' to be 'there'"
arr  = Split(strCurrentLine, "'")

For i = choice To UBound(arr) Step 2
  objCommentFile.Write arr(i)
Next
...

choice的价值是您的用户&#39;选择(1或2)。

请注意,要使其工作,字符串不得在其他任何地方包含撇号。正如@ Ekkehard.Horner在他的评论中所指出的那样,你不能在文本的其他地方使用分隔符(i'm),因为否则就无法区分它的目的是什么是分隔符和哪里不