WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Strings

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Finding Character Position in String

Keywords:        find locate itemlocate string functions

Question:

Is it possible to use ItemLocate to find the position of a particular character in a string, and then select the two characters to the left of the located character?

Answer:

Umm. No. This would require use of the string functions. Something like:

        DaString="ABCQXYZ"
        DaChar="Q"
        a=StrIndex(DaString,DaChar,0,@FWDSCAN)
        DaAnswer=StrSub(DaString,a-2,2)

More examples:

I'm interested in is some string manipulation tools, such as StrRight, StrLeft, StrMid, i.e be able to ask for the left 5 char's from a string, or from the right, or even say for the 6 chars 3rd from the left.

Here's an example using the StrSub function:

  1. Left 5 chars:
    newstring=strsub(oldstring,1,5) 
    
  2. Right 5 chars:
    newstring=strsub(oldstring, strlen(oldstring)-5,5) 
    
  3. 6 chars 3rd from left:
    newstring=strsub(oldstring,3,6) 
    

Article ID:   W13333
Filename:   Finding Character Position in String.txt
File Created: 2001:01:08:16:18:38
Last Updated: 2001:01:08:16:18:38