2013-05-29 4 views
0

"fullname"을 다음 URL의 값으로 대체해야합니다. "fullname"은 사전 정의 된 문자열이며 동적 값을 제공합니다. 내가 도움이 필요해, 어떻게 C#에서 그것을 할 ??C#에서 URL의 문자열을 연결하는 방법?

예를 들어 전체 이름을 듣고 = XYZ와 나는

string FullName="Mansinh"; 
string html = @"<a style=""width:100%%25;height:100%%25"" href=""http://kcs.kayako.com/visitor/index.php?/LiveChat/Chat/Request/_sessionID=34mh1inqnaeliioe3og5tious2t93ip9/_proactive=0/_filterDepartmentID=/_randomNumber=43/_fullName=XYZ/_email=usha%40kcspl.co.in/_promptType=chat"" target=""_blank""> <image style=""width:1340px;height:800px"" src=""/Images/1x1-pixel.png"" /> </a>"; 

답변

1

문자열 HTML = @ "http://kcs.kayako.com/visitor/index.php?/LiveChat/Chat/Request/_sessionID=34mh1inqnaeliioe3og5tious2t93ip9/_proactive=0/_filterDepartmentID=/_randomNumber=43/_fullName= /_email=usha%40kcspl.co.in/_promptType=chat ""대상 = ""_ 빈 ","> ","

는 + 문자열 당신은 +

을 원한다 ";

1

는 문자열을 연결하는 + 연산자를 사용 varible contacte 싶어한다. 예 : 당신의 캐릭터와

string html = @"asdf" + variable + @"asdf"; 

:

string html = @"<a style=""width:100%%25;height:100%%25"" href=""http://kcs.kayako.com/visitor/index.php?/LiveChat/Chat/Request/_sessionID=34mh1inqnaeliioe3og5tious2t93ip9/_proactive=0/_filterDepartmentID=/_randomNumber=43/_fullName=" + FullName + @"/_email=usha%40kcspl.co.in/_promptType=chat"" target=""_blank""> <image style=""width:1340px;height:800px"" src=""/Images/1x1-pixel.png"" /> </a>"; 
5
당신은 @로 구분 된 문자열로 변수를 연결할 때

string html = "asdf" + variable + "asdf"; 

것은, 또한 변수 후 리터럴 문자열에 @를 사용해야합니다

StringBuilder을 사용하거나 간단한 경우 + 연산자를 사용하십시오.

StringBuilder sb = new StringBuilder() 
sb.Append("The start of the string"); 
sb.Append(theFullNameVariable); 
sb.Append("the end of the string"); 
string fullUrl = sb.ToString(); 

또는

string fullUrl = "The start" + theFullNameVariable + "the end"; 

여러 문 대신 중 하나 이상을 사용하는 경우 특히, +을 사용하여 성능 저하가 있습니다. 그리고 내 실험에서 약 12 ​​개의 연결 이후에 StringBuilder을 사용하는 것이 더 빠르다는 것을 발견했습니다. YMMV

+1

+1 StringBuilder가 문자열 묶음보다 우수하다는 것을 나타 내기 위해 +1 –

관련 문제