0

I need to replace "fullname" with a value in following URL. "fullname" is a predefined string and it gives a dynamic value. I need help, How to do it in C# ??

for example hear full name=XYZ and i wants to contacte varible

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>";   

3 Answers 3

5

Use StringBuilder or for simple cases the + operator.

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();

Or

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

There is a performance penalty to using +, especially if you are using it over several statements instead of one. And in my experiments I've found that about after half a dozen concatenations it is faster to use StringBuilder. YMMV

Sign up to request clarification or add additional context in comments.

1 Comment

+1 for mentionning that StringBuilder's is better only after a bunch of strings
1

string html = @"http://kcs.kayako.com/visitor/index.php?/LiveChat/Chat/Request/_sessionID=34mh1inqnaeliioe3og5tious2t93ip9/_proactive=0/_filterDepartmentID=/_randomNumber=43/_fullName="

+any string you wants+

"/_email=usha%40kcspl.co.in/_promptType=chat"" target=""_blank""> ";

Comments

1

Use the + operator to concatenate strings. Example:

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

Remember to use @ on the literal string after the variable also, when you concatenate a variable into a @ delimited string:

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

With your string:

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>";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.