replacing text

Ask your TEXTools related questions here.

replacing text

Postby kumar » Thu Mar 11, 2010 1:51 pm

I have a file in which there is a line:

versionNumber="1.0.0". However, the 1.0.0 is not always the same. So, I need to look for word "versionNumber" and then get the value after "=",extract the first number after doublequote and increment the value. Assumption: it is always numeric after the doublequote.

How can I do this with "TEXTools"?

Please advise.
kumar
 
Posts: 1
Joined: Thu Mar 11, 2010 1:47 pm

Re: replacing text

Postby bwblock » Mon Apr 12, 2010 5:27 pm

kumar wrote:I have a file in which there is a line:

versionNumber="1.0.0". However, the 1.0.0 is not always the same. So, I need to look for word "versionNumber" and then get the value after "=",extract the first number after doublequote and increment the value. Assumption: it is always numeric after the doublequote.

How can I do this with "TEXTools"?

Please advise.


Sorry I missed seeing yours and the other initial posts to the forum. I thought I had email notification configured. Apparently not. :oops: Anyway, to answer your question, this can be done many different ways but all of the approaches must first isolate the text in order to update it without affecting the surrounding text. Here's one solution:

Code: Select all
IsolateLines 'versionNumber=' 'versionNumber='
   ShiftChars 20 '.'
   PadLinesRight ' ' /w29
   AppendStr '1'
   AddValues 16 30 /i20 /d0 /w0
   ReplStr '\s' '' '"\d' '"' /r
EndIsolate


Here's an approach using regular expressions:

Code: Select all
IsolateLines 'versionNumber=' 'versionNumber='
   ReplStr 'versionNumber="(\d+)(.+")' '1 \1 \2' /r
   AddValues 1 3 /i1 /d0 /w0
   ReplStr '^(\d+)\s\d+\s\d+\s+' 'versionNumber="\1' /r
EndIsolate


... and yet another that uses line rotation:

Code: Select all
IsolateLines 'versionNumber=' 'versionNumber='
   RotCharsLeftStr 1 '\d' /r
   ReplStr '\.' ' . ' '^(\d)' '1 \1 ' /r
   AddValues 1 3 /i1 /d0 /w0
   ReplStr '^(\d+)\s\d+\s\d+\s+' '\1' '\s' '' /r
   RotCharsLeftStr 1 'versionNumber'
EndIsolate
bwblock
Site Admin
 
Posts: 7
Joined: Thu Nov 26, 2009 11:50 am


Return to TEXTools Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron