Page 1 of 1

Reverse string - (for right to left searchs)

PostPosted: Thu May 19, 2011 6:29 am
by dpayer
I found the following function in VBscript that will reverse the order of a string. This is helpful if you want to do a right to left search. I created a function in NB that read each character and rewrote the order of the string. A 3k file took 20 seconds (!). With this VBscript it takes less than one second. Remember: if you are searching from right to left, remember to reverse the order of your searched item as well!.

This example expects a NB variable called [String2Reverse] and will give the resultant variable named [ReversedString]

Code: Select all
DIM String2Reverse
DIM ReversedString
String2Reverse = publication.nbGetVar( "[String2Reverse]" )
ReversedString = StrReverse( String2Reverse )
publication.nbSetVar "[ReversedString]", ReversedString

David P

PostPosted: Thu May 19, 2011 10:16 am
by Neosoft Support
Thanks David.

Re: Reverse string - (for right to left searchs)

PostPosted: Sun May 01, 2016 7:43 pm
by fkapnist
Thanks for this. I just used it to reverse a source code (=tnetnoc ATEM< from <META content=) thus making it easier to parse and trim a metadata tag that was at the end of a string instead of at the beginning....

Code: Select all
          If "[thevartitle]" "=" "0"
          SearchStr "property=[#34]og:image" "[thevar]" "[thevartitle]" ""

                    If "[thevartitle]" ">" "0"
                       StrParse "[thevar]" "property=[#34]og:image" "[varhead]" "[ogCount]"
                       SetVar "[String2Reverse]" "[varhead1]"
                       Call "ReverseString"
                       SetVar "[thevar]" "[ReversedString]"
                       StrParse "[thevar]" "=tnetnoc ATEM<" "[varhead]" "[ogCount]"
                       SetVar "[String2Reverse]" "[varhead1]"
                       Call "ReverseString"
                       StrReplace "[ReversedString]" "[#34]" "" "[readtitle]" "CaseSensitive"
                       GotoLine "showit"