Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello World!

I have written code to read and write data from a LEGO MINDSTORMS NXT Device via bluetooth. The data recieved is in ascii and they contain multiple bytes..each byte has a meaning to it..

One lenght is the device name and i need to convert it a string but i need to get this part of the textbox value which contains the ASCII value.

Do you have any way to do this...i have tried substring but it does not work?

HELP!! Any ideas?

Travis
Posted

hey! its bettter to access Individual character from string by using Square bracket on the string instance identifier. like
string str = "ABSDEFG";
char firstvalue = str[0];
char secondvalue = str[1];
char Thirdvalue = str[2];

and for last value is we can use str[str.length -1];
 
Share this answer
 
Comments
Travis Singh 28-Dec-11 20:11pm    
Thanks!!
If the data is received as bytes, all you need to do is convert it to a string:
C#
byte[] bytes = ...
string s = System.Text.Encoding.ASCII.GetString(bytes);



"I have....but how do i get individual parts of the string"

C#
byte[] bytes = ...
string s = System.Text.Encoding.ASCII.GetString(bytes);
string t = s.Substring(0, 5);       // First five characters
string u = s.Substring(2, 3);       // Third, fourth and fifth characters
string v = s.Substring(10);         // All characters from the 11th to the end
char x = s[4];                      // Fifth character

And so on...
 
Share this answer
 
v2
Comments
Travis Singh 28-Dec-11 6:39am    
I have....but how do i get individual parts of the string
OriginalGriff 28-Dec-11 7:56am    
Answer updated

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900