TechTalkz.com Logo

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Programing Languages > C#(C Sharp)

Notices

Convert strings to/from C# syntax?

C#(C Sharp)


Reply
 
Thread Tools Display Modes
Old 19-09-2007, 07:31 AM   #1
Michael A. Covington
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?



  Reply With Quote
Old 19-09-2007, 08:32 AM   #2
Nicholas Paldino [.NET/C# MVP]
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?
>
>
>


  Reply With Quote
Old 19-09-2007, 08:32 AM   #3
Michael A. Covington
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.



  Reply With Quote
Old 19-09-2007, 02:30 PM   #4
Niels Ull
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?
>>



  Reply With Quote
Reply

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?

All times are GMT +5.5. The time now is 09:13 AM.


vBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2009, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional