Reverse string - (for right to left searchs)

Questions and information about using VBScript and JavaScript in NeoBook functions

Moderator: Neosoft Support

Locked
User avatar
dpayer
Posts: 1394
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Reverse string - (for right to left searchs)

Post 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
Neosoft Support
NeoSoft Team
Posts: 5628
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA
Contact:

Post by Neosoft Support »

Thanks David.
NeoSoft Support
User avatar
fkapnist
Posts: 348
Joined: Mon Nov 17, 2014 4:24 pm
Location: Greece
Contact:

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

Post 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"
                    EndIf
          EndIf
:)
.
Locked