![]() |
|
|||||||
| Notices |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Guest
Posts: n/a
|
Convert strings to/from C# syntax?
Is there a built-in way to convert strings to and from their syntactic
representation in C#? For example, suppose I have a string containing 'a' and a newline character and 'b'. Is there some built-in way to render this as a string containing the characters 'a' '\' 'n' 'b' ? And the inverse? |
|
|
|
#2 |
|
Guest
Posts: n/a
|
Re: Convert strings to/from C# syntax?
Michael,
Do you mean you want a stirng literal like this: "a\nb" Or are you looking for a routine which will take the above literal and give you the equivalent of: "a\\nb" Which when printed will give you "a\nb". If it is the latter, then AFAIK, the answer is no, you would have to code this yourself. -- - Nicholas Paldino [.NET/C# MVP] - "Michael A. Covington" <.edu.for.address> wrote in message news:.gbl... > Is there a built-in way to convert strings to and from their syntactic > representation in C#? > > For example, suppose I have a string containing 'a' and a newline > character and 'b'. Is there some built-in way to render this as a string > containing the characters 'a' '\' 'n' 'b' ? > > And the inverse? > > > |
|
|
|
#3 |
|
Guest
Posts: n/a
|
Re: Convert strings to/from C# syntax?
"Nicholas Paldino [.NET/C# MVP]" <> wrote in message news:... > Michael, > > Do you mean you want a stirng literal like this: > > "a\nb" > > Or are you looking for a routine which will take the above literal and > give you the equivalent of: > > "a\\nb" > > Which when printed will give you "a\nb". If it is the latter, then > AFAIK, the answer is no, you would have to code this yourself. The latter. Thanks. |
|
|
|
#4 |
|
Guest
Posts: n/a
|
Re: Convert strings to/from C# syntax?
> Michael,
> > Do you mean you want a stirng literal like this: > > "a\nb" > > Or are you looking for a routine which will take the above literal > and give you the equivalent of: > > "a\\nb" > > Which when printed will give you "a\nb". If it is the latter, > then AFAIK, the answer is no, you would have to code this yourself. Well, it is probably much easier to code it yourself, but you could use the CodeDOM, e.g. string myString = "a\nb"; CodePrimitiveExpression strExp = new CodePrimitiveExpression(mystring); CSharpCodeProvider csharpcodeprovider = new CSharpCodeProvider(); StringWriter result = new StringWriter(); csharpcodeprovider.GenerateCodeFromExpression(strE xp, result, new CodeGeneratorOptions()); return result.ToString(); Regards Niels Harremoës > > "Michael A. Covington" <.edu.for.address> wrote in message > news:.gbl... > >> Is there a built-in way to convert strings to and from their >> syntactic representation in C#? >> >> For example, suppose I have a string containing 'a' and a newline >> character and 'b'. Is there some built-in way to render this as a >> string containing the characters 'a' '\' 'n' 'b' ? >> >> And the inverse? >> |
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Bibliography XSL "/*/b:Locals/b:Local[@LCID=$_LCID]/b:Strings/b:RetrievedFromCap" | mitja decman | Microsoft Office | 1 | 26-09-2007 12:14 PM |
| Strings | AA2e72E | C#(C Sharp) | 19 | 19-09-2007 01:31 PM |
| Connection Strings - 4 a Newbie | Miro | VB.NET | 1 | 07-09-2007 05:31 PM |
| Searching for strings in Vista using Windows Explorer doesn't seem to work | Celegans | Windows Vista All | 3 | 19-08-2007 04:24 PM |
| VISTA TUTORIAL: Add Customized Strings in System Properties Dialog Box | Vishal Gupta | Guides | 0 | 08-02-2007 03:06 PM |
< Windows Help - MS Office Help - Hardware Support >
| New To Site? | Need Help? |