2012-05-28 3 views
0

의 사용은 내가 가진 모두 StringBuilder & 문자열 클래스 경로 저장 : 나는 여러 가지를 시도하지만 항상 serverName.Replace("\\", @"\"); 아무튼 사용문자열과

\ 갖는 문자열 결과

StringBuilder name = new StringBuilder(); 
name.Append(@"NETWORK\MyComputer"); 
String serverName = name.ToString(); //this converts the \ to a \\ 

을 작동하지 않으면 \

servername.Replace("\\", "\"");이 여전히 올바르지 않은 문자열로 "을 추가합니다.

도와주세요.

+2

무엇을하려고하십니까? 이 "질문"에 물음표가 없습니다. –

+0

연결 문자열을 만들려고 시도했지만 \\ 문제가 아니라 방금 해결 한 다른 문제로 보입니다. 도와 주셔서 감사합니다. – Craig

+2

@Craig - "그게 다른 것"이라고 말하기보다는 대답이 무엇인지 (또는 답변을 게시해야 함) 언급해야합니다. 귀하의 질문/답변은 향후 누군가에게 유용 할 수 있습니다. – slugster

답변

2

문자열 \에서 사용

name.Append(Path.Combine("NETWORK", "MyComputer"); 

는 이스케이프 시퀀스입니다. 그래서 디버거에서 \\\

Acc.to MSDN

Character combinations consisting of a backslash (\) followed by a letter or by a combination of digits are called "escape sequences." To represent a newline character, single quotation mark, or certain other characters in a character constant, you must use escape sequences. An escape sequence is regarded as a single character and is therefore valid as a character constant.

Escape sequences are typically used to specify actions such as carriage returns and tab movements on terminals and printers. They are also used to provide literal representations of nonprinting characters and characters that usually have special meanings, such as the double quotation mark ("). The following table lists the ANSI escape sequences and what they represent.

읽기 당신은 하나의 백 슬래시에 해당하는 경우 Escape Sequences

7

더블 백으로 표시되는 것 슬래시를 누른 다음 디버거에서 표시하는 방식입니다.

백 슬래시는 special character이며 두 배로 '특수성'이 꺼져 있습니다. 또는 @ 심볼을 소스 코드의 문자열에 접두어로 붙이면 사용하지 않아도됩니다.

+0

+1. 나를 때려. –

0

귀하의 코드를 컴파일 할 수 있다고 생각하지 않습니다. \는 이스케이프 문자이므로 "\" 문자열이 잘못됩니다. @ (리터럴)이 이스케이프를 무시하고 일반 문자로 사용하기 때문에 @"\"이 적합합니다.

더보기 here