Several functions of C ++ String

xiaoxiao2021-03-06  124

INT STRLEN (Const Char * Str) {Const Char * SC;

FOR (sc = str; * sc! = '/ 0'; sc);

Return SC - Str;}

Char * strtrim (char * s) {char * pdst = s;

While (1) {if (* pdst == '|| * pdst ==' / t '|| * pdst ==' / n ') {PDST ;} else {Break;}}

Char * p = pdst; while (* p) {p ;} p -; while (1) {if (* p == '' || * p == '/ t' || * p == '/ N ') {p -;} else {breaf;}} * (p 1) =' / 0 ';

Return PDST;

Char * strcat (char * DST, const char * src) {char * ptemp = dst;

While (* PTEMP) PTEMP ;

While (* PTEMP = * SRC );

Return dst;}

INT strcmp (const char * dst, const char * src) {int RET = 0; while (! (r = * dst - * src) && * dst) { src; Dst;}

IF (RET <0) RET = -1; ELSE IF (RET> 0) RET = 1;

Return Ret;}

INT strcmp (const char * dst, const char * src, int count) {int RET = 0; while (! (r = * dst - * src) && * dst) {if (--count == 0) Break; src; DST;}

IF (RET <0) RET = -1; ELSE IF (RET> 0) RET = 1;

Return Ret;}

Char * STRCPY (Char * DST, Const Char * src) {char * ptemp = DST;

While (* PTEMP = * SRC );

Return dst;}

Char * STRCPY (CHAR * DST, Const Char * src, int count) {char * ptemp = dst;

While (count - && (* PTEMP = * src );

Return dst;}

Char * strchr (const char * s, int c) {for (; * s! = (char) C; s) IF (* s == '/ 0') return null; return (char *) s; }

Char * STRCHR (const char * s, int C) {const char * p = s strlen (s); do {if (* p == (char) c) return (char *) p;} while P> = s); return null;}

Char * strstr (const char * s1, const char * s2) {INT L1, L2;

L2 = Strlen (S2); if (! l2) return (char *) S1; L1 = Strlen (S1); while (l1> = l2) {l1 -; if (! STRCMP (S1, S2, L2)) Return (char *) S1; S1 ;} return null;}

INT straspn (const char * s, const char * accept) {const char * p; const char * a; int count = 0;

For (p = s; * p! = '/ 0'; p) {for (a = accept; * a! = '/ 0'; a) {if (* p == * a) BREAK } if (* a == '/ 0') return count; count;}

Return count;

转载请注明原文地址:https://www.9cbs.com/read-126260.html

New Post(0)