Man*_*inh 0 string string-concatenation c#-4.0 windows-phone-8
我需要将"fullname"替换为以下URL中的值."fullname"是一个预定义的字符串,它给出了一个动态值.我需要帮助,如何在C#中做到这一点?
例如听到全名= 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>";
Run Code Online (Sandbox Code Playgroud)
使用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();
Run Code Online (Sandbox Code Playgroud)
要么
string fullUrl = "The start" + theFullNameVariable + "the end";
Run Code Online (Sandbox Code Playgroud)
使用时会有性能损失+,特别是如果您使用多个语句而不是一个语句.在我的实验中,我发现在六次连接后,使用起来更快StringBuilder.因人而异