Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


searching inside a string???????????

mharis1985mharis1985 Member Posts: 1
Hello everyone, my name is haris and I have recently started to learn basic. Right now a lot of things are looking very very difficult. I have downloaded couple on books on how to use liberty basic. And while every book tells the same function for searching inside a string instr function. I want to to know is it possible to search for two strings or numbers inside a string.

Here is a small example:
Print "what is the string?"
Input string$
Pos1 = instr$(string$,"a",1)
Pos2 = instr$(string$,"b",1)

I want to know is it possible to search for "a" and "b" in a single function?
Anyhelp will be greatly appreciated.


  • GWS01GWS01 Member Posts: 10
    Hello haris,

    The '1' in your example:

    [code]Pos1 = instr$(string$,"a",1)[/code]

    is optional, and simply means start searching string$ from the first character.

    So if you input the string "Where is my hat?", the value of Pos1 will be 14, since "a" is found at the 14th character position.

    Your second example:

    [code]Pos2 = instr$(string$,"b",1)[/code]

    will return Pos2 = 0, since the character "b" has not been found in the
    string "Where is my hat?".

    Your question is not very clear. The string to be searched for can be any number of characters. So if the input string had been "It's about time too", the following instr() statement will return a value for Pos1 = 6.

    [code]Pos1 = instr$(string$,"ab",1)[/code]

    which is where the string "ab" begins.

    To search for two independent strings, you would need to have two instr() statements to find where each began.

    hope that helps,


Sign In or Register to comment.