2013-08-05 3 views
0

사실 나는 문장에서 전체 단어를 바꾸길 원합니다. 나는 이 제발 도와주세요 여자에 없습니다 ... 단지이 모든 단어가 사람을 대체 할 | {불쾌한 여성 불쾌한 여성}C에서 문자열 조작 오류 #

기호가있는 사람 :하지만이 포함되어 있으며 하위 문자열 예에 대한

을 대체하는 기능을 대체 ... 미리 감사드립니다!

if(Init.SpintexEditorPropertyMain.SpinContent.Contains(spinkey) && spinkey != string.Empty) 
{ 
     Init.SpintexEditorPropertyMain.SpinContent = Init.SpintexEditorPropertyMain.SpinContent.Replace(spinkey, spinvalue); 
} 
+0

예상되는 결과는 무엇을 위해 사용 b를 \이

string a = "A man with a {unpleasant woman |disagreeable woman}"; string b = @"\bman\b"; string c = "men"; string str = Regex.Replace(a, b, c); 

를 시도? –

+1

이 페이지의 오른쪽에있는 링크 중 '관련'섹션 아래를 보았습니까? 찾으려는 답변으로 연결될 수있는 링크가 몇 가지 있습니다. – MethodMan

답변

3

정규식

 string input = "A man with a {unpleasant woman |disagreeable woman}"; 
     string output = Regex.Replace(input, @"\bman\b", "abc"); 
     Console.WriteLine(output); 

으로 시도합니다.

+0

정말 고마워요! –

2

"man"앞에 공백을 추가하여 "man"이라는 결과를 얻으십시오. :) 이것을 바꾸기 위해 사용하십시오. 그것은 "여자"에서 발견되지 않습니다. b는 단어 boundries을 의미 \

+3

대답이 아니라 .. 왜 수동으로 공백이나 빈칸을 추가하고 싶습니까? '대답이 아닌'그 대답에 기초하여 좋은 코더를 만들지는 않을 것입니다. – MethodMan

+1

@DJ KRAZE; 왜냐하면 그는 실제로 "남자"가 아닌 "남자"를 대체하기를 원하기 때문입니다. 대답입니다. –

+1

왜 대답이라고 생각하지 않습니까? – George87

1

단어 경계

+0

감사합니다. Pandiyan! –