c# literal conversion
-
Does anyone know of a class that can convert a string in the c# string literal format to a regular .NET string and vice versa? I want to have a designable string property that allows special characters and I figure a TypeConverter that supports the c# string literal format is probably the easiest way to do it, unless there exists a better way? Thanks
-
Does anyone know of a class that can convert a string in the c# string literal format to a regular .NET string and vice versa? I want to have a designable string property that allows special characters and I figure a TypeConverter that supports the c# string literal format is probably the easiest way to do it, unless there exists a better way? Thanks
Maybe some examples of the required conversion would be helpful...
Luc Pattyn
try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }
-
Maybe some examples of the required conversion would be helpful...
Luc Pattyn
try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }
Say you had a textbox with a property named "WhiteSpaceChars" of type string. Each char in the string is what should be a white space character. the default value for this string would be (in c# code) whiteSpaceChars = " \t\r\n"; Now I would like that string to show up in the property designer for users to be able to edit. Now obviously the default string TypeConverter in windows forms can't handle these particular characters. However if I had a TypeConverter that could handle the c# string literal syntax my problem would be solved. This goes both ways, if the user types in a value of \x00010 I would like the appropriate string returned to my class as if it were a string literal.
-
Say you had a textbox with a property named "WhiteSpaceChars" of type string. Each char in the string is what should be a white space character. the default value for this string would be (in c# code) whiteSpaceChars = " \t\r\n"; Now I would like that string to show up in the property designer for users to be able to edit. Now obviously the default string TypeConverter in windows forms can't handle these particular characters. However if I had a TypeConverter that could handle the c# string literal syntax my problem would be solved. This goes both ways, if the user types in a value of \x00010 I would like the appropriate string returned to my class as if it were a string literal.
Hi, if your only concern is the one backslash/two backslashes issue, you can convert back and forth with a simple method. I dont think it is provided by .NET, so you would have to write it yourself (I'll use curly braces to indicate a single char): say input is ab\tc\nd then output would have to be ab{TAB}c{NEWLINE}d you can do sequential replacement of \t by {TAB}, then \n by {NEWLINE} etc using String.Replace the order is irrelevant, since old and new strings do not conflict with each other. similar method is required for the other direction. if you also want to replace the \x#### and \u#### character codes by their actual char, things become more complicated. Do you ? :)
Luc Pattyn
try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }
-
Hi, if your only concern is the one backslash/two backslashes issue, you can convert back and forth with a simple method. I dont think it is provided by .NET, so you would have to write it yourself (I'll use curly braces to indicate a single char): say input is ab\tc\nd then output would have to be ab{TAB}c{NEWLINE}d you can do sequential replacement of \t by {TAB}, then \n by {NEWLINE} etc using String.Replace the order is irrelevant, since old and new strings do not conflict with each other. similar method is required for the other direction. if you also want to replace the \x#### and \u#### character codes by their actual char, things become more complicated. Do you ? :)
Luc Pattyn
try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }
Yeah I think you're right, a tagged expression would be much more easily parsed. Even a {x####} and {u####} could be easily extracted with some simple regexps. Thanks!