Search code examples
qbasic

how to search for a sub string within a string in QBasic


I am creating a simple chat programme in QBasic that will answer questions based on some specific key words present in the user input.therefore I need a way to search for a sub string (I.e. A specific word)within a string. So, please help me.


Solution

  • To find out if a string contains a certain (sub-)string, you can do this:

    text$ = "nonsense !"
    IF INSTR( text$, "sense" ) >= 1 THEN
      PRINT "This text makes sense !"
    END IF
    

    And no, I was not able to test this, as a no longer have QBasic on my PC ;-) According to the link from the comment above >= 1 is ok