String matching: Difference between revisions
Content added Content deleted
(jq) |
|||
Line 666: | Line 666: | ||
2 |
2 |
||
1</pre> |
1</pre> |
||
=={{header|DCL}}== |
|||
<lang DCL>$ first_string = p1 |
|||
$ length_of_first_string = f$length( first_string ) |
|||
$ second_string = p2 |
|||
$ length_of_second_string = f$length( second_string ) |
|||
$ offset = f$locate( second_string, first_string ) |
|||
$ if offset .eq. 0 |
|||
$ then |
|||
$ write sys$output "first string starts with second string" |
|||
$ else |
|||
$ write sys$output "first string does not start with second string" |
|||
$ endif |
|||
$ if offset .ne. length_of_first_string |
|||
$ then |
|||
$ write sys$output "first string contains the second string at some location" |
|||
$ else |
|||
$ write sys$output "first string does not contain the second string at any location" |
|||
$ endif |
|||
$ temp = f$extract( length_of_first_string - length_of_second_string, length_of_second_string, first_string ) |
|||
$ if second_string .eqs. temp |
|||
$ then |
|||
$ write sys$output "first string ends with the second string" |
|||
$ else |
|||
$ write sys$output "first string does not end with the second string" |
|||
$ endif</lang> |
|||
{{out}} |
|||
<pre>$ @string_matching efabcdef ef |
|||
first string starts with second string |
|||
first string contains the second string at some location |
|||
first string ends with the second string |
|||
$ @string_matching efabcdef ab |
|||
first string does not start with second string |
|||
first string contains the second string at some location |
|||
first string does not end with the second string |
|||
$ @string_matching efabcdef def |
|||
first string does not start with second string |
|||
first string contains the second string at some location |
|||
first string ends with the second string |
|||
$ @string_matching efabcdef defx |
|||
first string does not start with second string |
|||
first string does not contain the second string at any location |
|||
first string does not end with the second string</pre> |
|||
=={{header|Delphi}}== |
=={{header|Delphi}}== |