Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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

mharis1985mharis1985 Posts: 1Member
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.
[code][/code][code][/code]

Comments

  • GWS01GWS01 Posts: 10Member
    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,

    Graham


Sign In or Register to comment.