| View previous topic :: View next topic |
| Author |
Message |
lolAnonymous Expert Cheater
Reputation: 1
Joined: 19 Jul 2015 Posts: 154
|
Posted: Wed Dec 07, 2016 10:31 am Post subject: C# String And Byte Array Problem |
|
|
Hey guys.
1) I want to Initialize a string variable with the value :
" {"gamesHistory":"{\"18427757055\":[{\"userName\":\"hask\",\"winner\":true,\"userID\":\"291\"},{\"userName\":\"nae\",\"winner\":false,\"userID\":\"928\"} "
2) I want to use byte in for loop and concatenate in between of a byte array for example:
for(byte k = 0;k<100;k++)
{
byte[] lol = {0x00,0x23,0x81} // here I want to replace 23 with the value of k
}
Thanks In Advance
|
|
| Back to top |
|
 |
Zanzer I post too much
Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Wed Dec 07, 2016 2:05 pm Post subject: |
|
|
I can only assume you actually wanted:
| Code: | | string myvar = " {\"gamesHistory\":{\"18427757055\":[{\"userName\":\"hask\",\"winner\":true,\"userID\":\"291\"},{\"userName\":\"nae\",\"winner\":false,\"userID\":\"928\"}]}} " |
https://msdn.microsoft.com/en-us/library/system.buffer.blockcopy(v=vs.110).aspx?cs-save-lang=1&cs-lang=csharp
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Wed Dec 07, 2016 3:14 pm Post subject: |
|
|
1. As Zanzer showed, you need to escape the double-quotes that are not containing the string and are part of the string via \".
2. You haven't really given that great of an explanation. Your description and your comment in the code contradict themselves.
_________________
- Retired. |
|
| Back to top |
|
 |
lolAnonymous Expert Cheater
Reputation: 1
Joined: 19 Jul 2015 Posts: 154
|
Posted: Wed Dec 07, 2016 8:14 pm Post subject: |
|
|
Thank guys for your answers...
1) Actually the problem is \" is a part of string and Compiler is taking it as a escape sequence...
2) leave this problem for now I think I will not need this if 1st is solved
Thanks In Advance
|
|
| Back to top |
|
 |
Zanzer I post too much
Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Wed Dec 07, 2016 11:24 pm Post subject: |
|
|
| Code: | | string myvar = @" {\""gamesHistory\"":{\""18427757055\"":[{\""userName\"":\""hask\"",\""winner\"":true,\""userID\"":\""291\""},{\""userName\"":\""nae\"",\""winner\"":false,\""userID\"":\""928\""}]}} " |
| Code: | | string myvar = " {\\\"gamesHistory\\\":{\\\"18427757055\\\":[{\\\"userName\\\":\\\"hask\\\",\\\"winner\\\":true,\\\"userID\\\":\\\"291\\\"},{\\\"userName\\\":\\\"nae\\\",\\\"winner\\\":false,\\\"userID\\\":\\\"928\\\"}]}} " |
|
|
| Back to top |
|
 |
lolAnonymous Expert Cheater
Reputation: 1
Joined: 19 Jul 2015 Posts: 154
|
Posted: Thu Dec 08, 2016 12:50 am Post subject: |
|
|
Thanks Zanzer your answer solved the problem..
Thanks Zanzer and aom0s for both of your time
|
|
| Back to top |
|
 |
Zanzer I post too much
Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Thu Dec 08, 2016 6:18 pm Post subject: |
|
|
By the way, string literals and escape characters are something you learn about on day one.
You really ought to watch some introductory course on C# before jumping into trainers.
Help for you might be running out if you continue with questions like these.
|
|
| Back to top |
|
 |
|