String matching: Difference between revisions

Content deleted Content added
Eriksiers (talk | contribs)
m alphabetized list
Eriksiers (talk | contribs)
added basic
Line 40: Line 40:
'ab' appears in 'abab' 2 times
'ab' appears in 'abab' 2 times
</pre>
</pre>

=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==
{{trans|python}}
{{trans|python}}
Line 85: Line 86:
MsgBox, "%String1%" ends with "%String2%".
MsgBox, "%String1%" ends with "%String2%".
</lang>
</lang>

=={{header|BASIC}}==
{{works with|QBasic}}
<lang qbasic>first$ = "qwertyuiop"

'Determining if the first string starts with second string
second$ = "qwerty"
IF LEFT$(first$, LEN(second$)) = second$ THEN
PRINT "'"; first$; "' starts with '"; second$; "'"
ELSE
PRINT "'"; first$; "' does not start with '"; second$; "'"
END IF

'Determining if the first string contains the second string at any location
'Print the location of the match for part 2
second$ = "wert"
x = INSTR(first$, second$)
IF x THEN
PRINT "'"; first$; "' contains '"; second$; "' at position "; x
ELSE
PRINT "'"; first$; "' does not contain '"; second$; "'"
END IF

' Determining if the first string ends with the second string
second$ = "random garbage"
IF RIGHT$(first$, LEN(second$)) = second$ THEN
PRINT "'"; first$; "' ends with '"; second$; "'"
ELSE
PRINT "'"; first$; "' does not end with '"; second$; "'"
END IF

</lang>

Output:
'qwertyuiop' starts with 'qwerty'
'qwertyuiop' contains 'wert' at position 2
'qwertyuiop' does not end with 'random garbage'


=={{header|C}}==
=={{header|C}}==