상세 컨텐츠

본문 제목

특정 문자열에서 숫자만 뽑아내기

C#

by 탑~! 2013. 6. 29. 16:45

본문

숫자만 추출할때 쓰면 된다.
using System.Text.RegularExpressions;
위의 네임스페이스를 추가해주어야 한다.


string strText = "abc1234567ㅏㅣ"

string strNum = "";

strNum = Regex.Replace(strText, @"\D", "");


이렇게 하면 숫자만 추출된다.

닷넷 정규식에서 \d는 숫자. \D는 숫자가 아닌 문자를 의미합니다.


MSDN에서 보기
Regex.Replace 메서드 (String, MatchEvaluator)
http://msdn2.microsoft.com/ko-kr/library/cft8645c(VS.80).aspx

관련글 더보기