문자열: 5개의 글
들어가며 파이썬에 내장되어 있는 함수 join, split을 이용해 문자열(String)을 리스트(List)로 변환하는 방법입니다. Join 함수는 리스트를 특정 구분자를 포함해 문자열로 변환해 주는 함수입니다. Split함수는 문자열을 특정 구분자를 기준으로 나누어 리스트로 변환해 주는 함수입니다. 리스트(List)를 특정 구분자를 포함해 문자열(String)으로 변환 animals = ['사자', '코끼리', '기린', '원숭이', '바나나원숭이'] print ",".join(animals) # >> 사자,코끼리,기린,원숭이,바나나원숭이 print "\n".join(animals) # >> 사자 # >> 코끼리 # >> 기린 # >> 원숭이 # >> 바나나원숭이 print "/".join(animal..
stod를 사용하면 된다. 그리고 자동적으로 앞뒤 공백까지 제거해주니 편하다 #include #include using namespace std; int main() { cout
STL을 사용하여 문자열을 뒤집을 수 있다. 현재 문자열 자체를 뒤집으므로 원본을 보존할 경우라면 복사해서 써야한다. #include #include #include int main() { std::string foo("foo"); std::string copy(foo); std::cout
Boost 라이브러리를 사용하지 않고 문자열 앞뒤 공백 제거할 수 있는 방법을 발견했다. 고마워요 스택오버플로우 // trim from left inline std::string& ltrim(std::string& s, const char* t = " \t\n\r\f\v") { s.erase(0, s.find_first_not_of(t)); return s; } // trim from right inline std::string& rtrim(std::string& s, const char* t = " \t\n\r\f\v") { s.erase(s.find_last_not_of(t) + 1); return s; } // trim from left & right inline std::string& trim(s..
sample_string = "1234567890abcdefgABCDEFG!@#$%^&*()_{}[]" result_string = "" for c in sample_string: if c.isalnum(): result_string +=c print result_string python 에서 텍스트를 처리할 때 특수문자를 제거해야 할 때가 있습니다. 이럴 때 정규표현식 으로 처리할 수도 있지만 다음과 같이 처리할 수도 있습니다. sample_string = "1234567890abcdefgABCDEFG!@#$%^&*()_{}[]" result_string = "" for c in sample_string: if c.isalnum(): result_string +=c print result_string ..