문자열 치환 함수 설명서
string_replace_all
함수는 문자열에서 특정 부분 문자열을 찾아서, 지정한 새로운 문자열로 모든 인스턴스를 교체하는 데 사용됩니다.
문법
string_replace_all(str, substr, newstr);
인수 설명
인수 | 타입 | 설명 |
---|---|---|
str | String | 파싱할 문자열입니다. |
substr | String | 문자열 내에서 교체할 부분 문자열입니다. |
newstr | String | 이전 문자열을 교체할 새로운 부분 문자열입니다. |
반환 값
- String: 교체된 문자열을 반환합니다.
예제
str1 = "Hexxo Worxd";
str2 = string_replace_all(str1, "x", "l");
위 코드는 str1
의 "x"를 "l"로 교체하여 str2
에 "Hello World"를 설정합니다.
활용 예제
- 사용자 입력 처리
gml user_input = "I love apples and bananas."; corrected_input = string_replace_all(user_input, "apples", "oranges");
- 파일 이름 정리
gml file_name = "my_file_2023.txt"; new_file_name = string_replace_all(file_name, "_", "-");
- HTML 태그 제거
gml html_string = "<p>Hello World!</p>"; clean_string = string_replace_all(html_string, "<p>", ""); clean_string = string_replace_all(clean_string, "</p>", "");
- 오타 수정
gml text = "I am a develper."; corrected_text = string_replace_all(text, "develper", "developer");
- 특수 문자 제거
gml message = "Hello @World!"; clean_message = string_replace_all(message, "@", "");
이와 같이 string_replace_all
함수를 활용하여 다양한 문자열 처리 작업을 수행할 수 있습니다.