소리소문 없이... 사랑도 명예도 이름도 남김 없이...
DexCore.net

C#

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

탑~! 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

728x90
반응형