Jump to content

String matching: Difference between revisions

added basic
m (alphabetized list)
(added basic)
Line 40:
'ab' appears in 'abab' 2 times
</pre>
 
=={{header|ALGOL 68}}==
{{trans|python}}
Line 85 ⟶ 86:
MsgBox, "%String1%" ends with "%String2%".
</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}}==
1,150

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.