haven't used C# in a long time and forgot how to convert a string to a bytearray. Anyone got a function to do it?
Printable View
haven't used C# in a long time and forgot how to convert a string to a bytearray. Anyone got a function to do it?
(new System.Text.Encoding.UTF8Encoding()).GetBytes(mystring)
Also is there a multiline function for strings?
Like lua(scripting langauge) you could do
Code:local multilinestring = [[this
is
a
multi line string]]
no, but you can put \n in a string for a new line.
That didnt work. UTF8Encoding() doesnt exist.Quote:
Originally Posted by penagate
System.Text.Encoding.UTF8.GetBytes(mystring)
Now is there an easy way to use " in strings?
"\""
Are there special quotes like in lua you can do [["anything in here"]] because it would take too long to add all those \ before the quotes.Quote:
Originally Posted by penagate
well, C# isn't lua.
Long string literals are a bad idea anyway, if you want long strings with quotes then put them in a resource file and load from there.
Also for paths, regular expressions and other things that contain lots of backslash characters you can prepend @ to disable escape sequence parsing so you don't have to escape \ as \\.
Code:string file_path = @"C:\blah\thing";
Now also i got a number as a string and am wondering how do i convert it to a number?
Use the Parse or TryParse method of the type you want to convert the string to. If you know for sure that the string represents a valid number then use the Parse method. If there's a chance that it may not be valid, like if it's been entered by the user in a TextBox, then use the TryParse method.Quote:
Originally Posted by high6