|
-
Jan 3rd, 2007, 04:52 PM
#1
Thread Starter
Frenzied Member
[2.0] string to byte array?
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?
-
Jan 3rd, 2007, 05:07 PM
#2
Re: [2.0] string to byte array?
(new System.Text.Encoding.UTF8Encoding()).GetBytes(mystring)
-
Jan 3rd, 2007, 05:18 PM
#3
Thread Starter
Frenzied Member
Re: [2.0] string to byte array?
Also is there a multiline function for strings?
Like lua(scripting langauge) you could do
Code:
local multilinestring = [[this
is
a
multi line string]]
-
Jan 3rd, 2007, 05:24 PM
#4
Re: [2.0] string to byte array?
no, but you can put \n in a string for a new line.
-
Jan 3rd, 2007, 05:37 PM
#5
Thread Starter
Frenzied Member
Re: [2.0] string to byte array?
 Originally Posted by penagate
(new System.Text.Encoding.UTF8Encoding()).GetBytes(mystring)
That didnt work. UTF8Encoding() doesnt exist.
-
Jan 3rd, 2007, 05:44 PM
#6
Re: [2.0] string to byte array?
System.Text.Encoding.UTF8.GetBytes(mystring)
-
Jan 3rd, 2007, 05:59 PM
#7
Thread Starter
Frenzied Member
Re: [2.0] string to byte array?
Now is there an easy way to use " in strings?
-
Jan 3rd, 2007, 06:00 PM
#8
Re: [2.0] string to byte array?
-
Jan 3rd, 2007, 06:04 PM
#9
Thread Starter
Frenzied Member
Re: [2.0] string to byte array?
 Originally Posted by penagate
"\""
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.
-
Jan 3rd, 2007, 06:06 PM
#10
Re: [2.0] string to byte array?
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";
-
Jan 3rd, 2007, 08:28 PM
#11
Thread Starter
Frenzied Member
Re: [2.0] string to byte array?
Now also i got a number as a string and am wondering how do i convert it to a number?
-
Jan 3rd, 2007, 08:49 PM
#12
Re: [2.0] string to byte array?
 Originally Posted by high6
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|