Source language: Translate to:

Reverse string - (for right to left searchs)

Questions and information about using VBScript and JavaScript in NeoBook functions

Moderator: Neosoft Support

Reverse string - (for right to left searchs)

Postby dpayer » Thu May 19, 2011 6:29 am

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
User avatar
Posts: 1380
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Postby Neosoft Support » Thu May 19, 2011 10:16 am

Thanks David.
NeoSoft Support
Neosoft Support
NeoSoft Team
Posts: 5593
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA

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

Postby fkapnist » Sun May 01, 2016 7:43 pm

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"

User avatar
Posts: 348
Joined: Mon Nov 17, 2014 4:24 pm
Location: Greece

Return to NeoBook Functions - VBScript & JavaScript

Who is online

Users browsing this forum: No registered users and 1 guest