Anonymous user
String matching: Difference between revisions
→{{header|C}}: Condensed in observation of the "Know thy standard library" commandment. Output fixed to put newlines at the end of lines.
(→{{header|Euphoria}}: Euphoria example added) |
(→{{header|C}}: Condensed in observation of the "Know thy standard library" commandment. Output fixed to put newlines at the end of lines.) |
||
Line 126:
=={{header|C}}==
Case sensitive matching:
<lang C>#include <string.h>
#include <
int startsWith(char* container, char* target)▼
▲int startsWith(char* container,char* target)
{
if (clen < tlen)
return strncmp(container, target, tlen) == 0;
▲ return true;
return false;▼
}
int endsWith(char* container, char* target)
{
if (clen < tlen)
return strncmp(container + clen - tlen, target, tlen) == 0;
}
int doesContain(char* container, char* target)
{
return strstr(container, target) != 0;
}
int main(void)
{
}</lang>▼
▲</lang>
Output :
<pre>Starts with Test ( Hello,Hell ) : 1▼
▲Starts with Test ( Hello,Hell ) : 1
Ends with Test ( Code,ode ) : 1
Contains Test ( Google,msn ) : 0</pre>
Code without using string library to demonstrate how char strings are just pointers:
<lang C>#include <stdio.h>
|