제 홈페이지에 예전에 정리해두었던 게시물입니다만, 배우고 계시는 분들께 도움이 될까 싶어서 한 번 올려봅니다.

------

C/C++ 언어에서는 문자열 조작함수도 원체 많아서 지금까지 모르고 왔던 것들이 많더군요.

그래서 이 참에 정리해보기로 마음먹었습니다.

함수에 대한 자세한 것은 MSDN의 Run-Time Library Reference -> String Manipulation에 실려 있었습니다.

# strnset: Initialize characters of a string to a given format.
char *strnset(char *string, int c, size_t count);

[ Example ]
Before: This is a test
After:  **** is a test


# strupr: Convert a string to uppercase.
# strlwr: Convert a string to lowercase.
char *strupr(char *string);
char *strlwr(char *string);


[ Example ]
Mixed: The String to End All Strings!
Lower: the string to end all strings!
Upper: THE STRING TO END ALL STRINGS!


# strset: Set characters of a string to a character.
char *strset(char *string, int c);

[ Example ]
Before: Fill the string with something
After:  ******************************


# strrev: Reverse characters of a string.
char *strrev(char *string);

[ Example ]
Before: ABC
After: CBA


# strdup: Duplicate strings.
char *strdup(const char *strSource);

[ Example ]
Original: This is the buffer text
Copy:     This is the buffer text


# strstr: Returns a pointer to the first occurrence of a search string in a string.
char *strstr(const char *string, const char *strSearch);

[ Example ]
String: The quick brown dog jumps over the lazy fox
Result: lazy found at position 36


# strchr: Find a character in a string.
# strrchr: Scan a string for the last occurrence of a character.
char *strchr(const char *string, int c);
char *strrchr(const char *string, int c);

[ Example ]
String: The quick brown dog jumps over the lazy fox
Result: first r found at position 12
Result: last r found at position 30


# strtok: Find the next token in a string.
char *strtok(char *strToken, const char *strDelimit);

[ Example ]
String: The quick brown dog jumps over the lazy fox
Delimit: (Space)
First Token: The
Second Token: quick
Third Token: brown
...