replace
-
Hi, This is what I have which is assigned to a string variable. I would like to replace the \\ to \ How is this done please? I tried: string strData = strData.Replace("\\", @"\") But it does not work. Thanks strData = "{\\rtf1\\ansi\\ansicpg1252\\uc1\\deff0{\\fonttbl\r\n{\\f0\\fswiss\\fcharset0\\fprq2 Arial;}\r\n{\\f1\\froman\\fcharset2\\fprq2 Symbol;}}\r\n{\\colortbl;\\red0\\green0\\blue0;\\red255\\green255\\blue255;}\r\n{\\stylesheet{\\s0\\itap0\\f0\\fs24 [Normal];}{\\*\\cs10\\additive Default Paragraph Font;}}\r\n{\\*\\generator TX_RTF32 12.0.500.501;}\r\n\\deftab1134\\paperw12240\\paperh15840\\margl1440\\margt1440\\margr1440\\margb1440\\pard\\itap0\\plain\\f0\\fs24 is is\\plain\\f0\\fs20 to \\plain\\f0\\fs20\\i confirm\\plain\\f0\\fs20\\par for \\plain\\f0\\fs20\\ul testing\\plain\\f0\\fs20\\b reasons...\\par }"
-
Hi, This is what I have which is assigned to a string variable. I would like to replace the \\ to \ How is this done please? I tried: string strData = strData.Replace("\\", @"\") But it does not work. Thanks strData = "{\\rtf1\\ansi\\ansicpg1252\\uc1\\deff0{\\fonttbl\r\n{\\f0\\fswiss\\fcharset0\\fprq2 Arial;}\r\n{\\f1\\froman\\fcharset2\\fprq2 Symbol;}}\r\n{\\colortbl;\\red0\\green0\\blue0;\\red255\\green255\\blue255;}\r\n{\\stylesheet{\\s0\\itap0\\f0\\fs24 [Normal];}{\\*\\cs10\\additive Default Paragraph Font;}}\r\n{\\*\\generator TX_RTF32 12.0.500.501;}\r\n\\deftab1134\\paperw12240\\paperh15840\\margl1440\\margt1440\\margr1440\\margb1440\\pard\\itap0\\plain\\f0\\fs24 is is\\plain\\f0\\fs20 to \\plain\\f0\\fs20\\i confirm\\plain\\f0\\fs20\\par for \\plain\\f0\\fs20\\ul testing\\plain\\f0\\fs20\\b reasons...\\par }"
-
Hi, This is what I have which is assigned to a string variable. I would like to replace the \\ to \ How is this done please? I tried: string strData = strData.Replace("\\", @"\") But it does not work. Thanks strData = "{\\rtf1\\ansi\\ansicpg1252\\uc1\\deff0{\\fonttbl\r\n{\\f0\\fswiss\\fcharset0\\fprq2 Arial;}\r\n{\\f1\\froman\\fcharset2\\fprq2 Symbol;}}\r\n{\\colortbl;\\red0\\green0\\blue0;\\red255\\green255\\blue255;}\r\n{\\stylesheet{\\s0\\itap0\\f0\\fs24 [Normal];}{\\*\\cs10\\additive Default Paragraph Font;}}\r\n{\\*\\generator TX_RTF32 12.0.500.501;}\r\n\\deftab1134\\paperw12240\\paperh15840\\margl1440\\margt1440\\margr1440\\margb1440\\pard\\itap0\\plain\\f0\\fs24 is is\\plain\\f0\\fs20 to \\plain\\f0\\fs20\\i confirm\\plain\\f0\\fs20\\par for \\plain\\f0\\fs20\\ul testing\\plain\\f0\\fs20\\b reasons...\\par }"
C# reads "\\" as one slash, so type "\\\\" instead
-
C# reads "\\" as one slash, so type "\\\\" instead
sorry, did not see other post - tired :S
-
Hi, This is what I have which is assigned to a string variable. I would like to replace the \\ to \ How is this done please? I tried: string strData = strData.Replace("\\", @"\") But it does not work. Thanks strData = "{\\rtf1\\ansi\\ansicpg1252\\uc1\\deff0{\\fonttbl\r\n{\\f0\\fswiss\\fcharset0\\fprq2 Arial;}\r\n{\\f1\\froman\\fcharset2\\fprq2 Symbol;}}\r\n{\\colortbl;\\red0\\green0\\blue0;\\red255\\green255\\blue255;}\r\n{\\stylesheet{\\s0\\itap0\\f0\\fs24 [Normal];}{\\*\\cs10\\additive Default Paragraph Font;}}\r\n{\\*\\generator TX_RTF32 12.0.500.501;}\r\n\\deftab1134\\paperw12240\\paperh15840\\margl1440\\margt1440\\margr1440\\margb1440\\pard\\itap0\\plain\\f0\\fs24 is is\\plain\\f0\\fs20 to \\plain\\f0\\fs20\\i confirm\\plain\\f0\\fs20\\par for \\plain\\f0\\fs20\\ul testing\\plain\\f0\\fs20\\b reasons...\\par }"
I think that you should look at the real problem, not just the symptom. Why do you have a string that contains double backslashes? Where does the string come from? I see that you also have escape codes like \r and \n in the string. If you don't handle them first, you will end up with a string that contains some "\r" that means Carrege Return, and some that doesn't. --- b { font-weight: normal; }
-
I think that you should look at the real problem, not just the symptom. Why do you have a string that contains double backslashes? Where does the string come from? I see that you also have escape codes like \r and \n in the string. If you don't handle them first, you will end up with a string that contains some "\r" that means Carrege Return, and some that doesn't. --- b { font-weight: normal; }
-
Guffa wrote:
Why do you have a string that contains double backslashes? Where does the string come from?
Looks like an RTF file header.
-
Yes, I recognise the rtf code, but that is not the point. Where does the string come from, as it contains escaped characters? If it would have been read from an rtf file, it woudln't. --- b { font-weight: normal; }
Why does this matter? You can have a hardcoded rtf string somewhere to preset the contents of a RichTextBox for example, and the sample the original author gave here looks just like such a case. Besides it seems to be perfectly good rtf, he just misinterpreted the escaped backslashes... Regards, mav
-
Why does this matter? You can have a hardcoded rtf string somewhere to preset the contents of a RichTextBox for example, and the sample the original author gave here looks just like such a case. Besides it seems to be perfectly good rtf, he just misinterpreted the escaped backslashes... Regards, mav
-
Why does this matter? You can have a hardcoded rtf string somewhere to preset the contents of a RichTextBox for example, and the sample the original author gave here looks just like such a case. Besides it seems to be perfectly good rtf, he just misinterpreted the escaped backslashes... Regards, mav
mav.northwind wrote:
Why does this matter? You can have a hardcoded rtf string somewhere to preset the contents of a RichTextBox for example, and the sample the original author gave here looks just like such a case.
If it were a hardcoded string, the obvious solution would of course be to correct the string in the code instead of correcting it afterwards.
mav.northwind wrote:
Besides it seems to be perfectly good rtf, he just misinterpreted the escaped backslashes...
If it really was actual code that the original author showed, the problem does not exist at all, so the correct solution would be to do nothing at all. What the best solution is, is still unknown until we know where the string comes from. That why I asked. --- b { font-weight: normal; } -- modified at 3:58 Thursday 2nd February, 2006
-
I agree. What does it matter where the string came from? He simply wanted to know how to fix the string by replacing the double backslashes with singles. Problem was solved. -Jason
jasonpb wrote:
What does it matter where the string came from? He simply wanted to know how to fix the string by replacing the double backslashes with singles. Problem was solved.
As the string contains both escaped control characters and escaped backslashes, simply replacing the backslashes will not solve the whole problem. It's not very uncommon that the real problem is different from what the original poster thinks. If you then only answer the question, you haven't solved the problem. Many times I have not only provided the correct answer, but also the correct question. Just because people don't know what to ask for, should we deprave them of a good answer? --- b { font-weight: normal; }
-
mav.northwind wrote:
Why does this matter? You can have a hardcoded rtf string somewhere to preset the contents of a RichTextBox for example, and the sample the original author gave here looks just like such a case.
If it were a hardcoded string, the obvious solution would of course be to correct the string in the code instead of correcting it afterwards.
mav.northwind wrote:
Besides it seems to be perfectly good rtf, he just misinterpreted the escaped backslashes...
If it really was actual code that the original author showed, the problem does not exist at all, so the correct solution would be to do nothing at all. What the best solution is, is still unknown until we know where the string comes from. That why I asked. --- b { font-weight: normal; } -- modified at 3:58 Thursday 2nd February, 2006
I think the simple explanation is that fmardani pasted something into his RTB and looked at the
Rtf
property in the VS debugger. I guess that's what a lot of people do in the beginning to get into rtf. That's exactly the format you get there (including the missing semicolon after his strData = ... assignment) :) But you're right, the RTF string itself is not the real source for the author's problems but a general misunderstanding regarding escaped characters and the '@' notation. Regards, mav