Dawie de Villiers
asked on
Append "/" to a string
How do i append the character \ to a string
rtf = rtf + @"\"; this is not working nor is this
rtf = rtf + "\\"; neither this
rtf = rtf + "\"; //this doesnt work escape
rtf = rtf + @"\"; this is not working nor is this
rtf = rtf + "\\"; neither this
rtf = rtf + "\"; //this doesnt work escape
you use string.Format
rtf = string.Format(@"{0}\", rtf);
rtf = string.Format(@"{0}\", rtf);
i tried this and it worked correctly
string rtf = string.Empty;
rtf += @"\";
string rtf = string.Empty;
rtf += @"\";
this will work:
rtf = rtf + @"\\";
rtf = rtf + @"\\";
Use this code snippet, I'm sure it's OK.
You may not initialize empty value for rtf variable?
You may not initialize empty value for rtf variable?
private void Func()
{
String rtf = "";
rtf = rtf + @"\";
rtf = rtf + "\\";
}
The author question is: how to APPEND a backslash to a RTF text
The backslash is a very special character in RTF, so you will need to escape it with a double backslash.
If you start with an empty rtf, then a single backslash can be shown, but I guess that's not what the author is asking for.
The backslash is a very special character in RTF, so you will need to escape it with a double backslash.
If you start with an empty rtf, then a single backslash can be shown, but I guess that's not what the author is asking for.
ASKER
rtf = "Testing Image Embading<br />\r\n<img alt=\"\" src=\"/Web%20Cleint/Home%2 0Page/Imag es/Stop.pn g\" /><br />\r\nEmage Embabeded here\r\n"
Regex exp = new Regex(@"img (alt=\.)?([^\.]+)\.png", RegexOptions.IgnoreCase);
string InputText = rtf;
MatchCollection MatchList = exp.Matches(InputText);
Match FirstMatch = MatchList[0];
for (int i = 0; i < MatchList.Count; i++)
{
string str = @"\";
string rtf1 = rtf.Replace("alt=\"\" src=\"/Web%20Cleint/Home%2 0Page/Imag es/Stop.pn g\"", rep);
string strToReplace; //= MatchList[i].ToString(); //;+ str;
//strToReplace = strToReplace.Substring(0, strToReplace.Length);
strToReplace = string.Format(@"{0}\", MatchList[i].ToString());
rtf = rtf.Replace(strToReplace, rep);
i hard corded rtf1 and it worked fine so what i want is for strToReplace to be equal to this string Web%20Cleint/Home%20Page/I mages/Stop .png\"
and im trying to achieve that by using this string string strToReplace; //= MatchList[i].ToString() + str;
it appends 2 \\ and doesnt match the other string
I hope this will help.
Regex exp = new Regex(@"img (alt=\.)?([^\.]+)\.png", RegexOptions.IgnoreCase);
string InputText = rtf;
MatchCollection MatchList = exp.Matches(InputText);
Match FirstMatch = MatchList[0];
for (int i = 0; i < MatchList.Count; i++)
{
string str = @"\";
string rtf1 = rtf.Replace("alt=\"\" src=\"/Web%20Cleint/Home%2
string strToReplace; //= MatchList[i].ToString(); //;+ str;
//strToReplace = strToReplace.Substring(0, strToReplace.Length);
strToReplace = string.Format(@"{0}\", MatchList[i].ToString());
rtf = rtf.Replace(strToReplace, rep);
i hard corded rtf1 and it worked fine so what i want is for strToReplace to be equal to this string Web%20Cleint/Home%20Page/I
and im trying to achieve that by using this string string strToReplace; //= MatchList[i].ToString() + str;
it appends 2 \\ and doesnt match the other string
I hope this will help.
ASKER
Guys this is what im doing for now
string str = "\"";
strToReplace = strToReplace + str and i will have to remove the additonal " after this string.
Is this the best way to do this?????
I dont know if i have to close the question or not
string str = "\"";
strToReplace = strToReplace + str and i will have to remove the additonal " after this string.
Is this the best way to do this?????
I dont know if i have to close the question or not
ASKER
Thank you very much
> string str = "\"";
is to append a double quote to the string...
which is not what you "asked" for?
I guess you don't want to tell us the "big picture"?
is to append a double quote to the string...
which is not what you "asked" for?
I guess you don't want to tell us the "big picture"?
your last comments are confusing and unrelated with your original question...
ASKER
string str = "\"";
string rtf1 = rtf.Replace("alt=\"\" src=\"/Web%20Cleint/Home%2 0Page/Imag es/Stop.pn g\"", rep);
string strToReplace = MatchList[i].ToString()+ str;
rtf = rtf.Replace(strToReplace, rep);
I asked for assistance on how to add a \ on my string, and as a highlited earlier on if
MatchList[i].ToString() = "alt=\"\" src=\"/Web%20Cleint/Home%2 0Page/Imag es/Stop.pn g ", my replace function wasnt working so i needed to add a single \ to the matchlist and so during run time @"\" will add two \\.
May you please append string str = "\""; to one string and do a replace at runtime and observe the results and do the same with str = @"\"; it wont work coz its got 2 \\.
I sorry for the confusion this might have caused.
string rtf1 = rtf.Replace("alt=\"\" src=\"/Web%20Cleint/Home%2
string strToReplace = MatchList[i].ToString()+ str;
rtf = rtf.Replace(strToReplace, rep);
I asked for assistance on how to add a \ on my string, and as a highlited earlier on if
MatchList[i].ToString() = "alt=\"\" src=\"/Web%20Cleint/Home%2
May you please append string str = "\""; to one string and do a replace at runtime and observe the results and do the same with str = @"\"; it wont work coz its got 2 \\.
I sorry for the confusion this might have caused.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
can you clarify "not working", please?