0

i need to replace a string timestamp(n) with a fix string6) in vbs. where n can be any value and find string should be case insensitive.

strLine = fle1.ReadLine

'strLine = (replace(strLine,"TIMESTAMP(0)","TIMESTAMP(6) ")

Please help me this for any value of n.

1
  • Could you show an example (or multiple examples of) strline and what your desired output would be. It's not clear what you mean by TIMESTAMP(0), TIMESTAMP(6), and STRING(6) since VBS doesn't have any of those types natively and the languages that do, differ in how they are formatted. Commented Jun 8, 2016 at 18:51

3 Answers 3

1

Use a Regexp .Replace:

>> Set r = New RegExp
>> r.Pattern = "TIMESTAMP\(\d+\)"
>> For Each s In Split("TIMESTAMP(1) TIMESTAMP(11) TIMESTAMP(9)")
>>     WScript.Echo s, r.Replace(s, "TIMESTAMP(6)")
>> Next
>>
TIMESTAMP(1) TIMESTAMP(6)
TIMESTAMP(11) TIMESTAMP(6)
TIMESTAMP(9) TIMESTAMP(6)
Sign up to request clarification or add additional context in comments.

Comments

0

You can use Replace but you can't omit any of the optional parameters.

strLine = Replace(fle1.ReadLine, "TIMESTAMP(0)", "TIMESTAMP(6) ", 1, -1, 1)

Comments

0
Set regEx = CreateObject("VBScript.RegExp")
    'regEx.Pattern = "(TIMESTAMP\([0-9].?\))"
    'regEx.IgnoreCase = True

    'strLine=regEx.Replace(strLine, "TIMESTAMP(6)")

I finally did it as i am very new to it, but learning things btw many thanks for help.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.