Click here to Skip to main content
15,905,068 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Developer,
Anybody give me conversion code for assigning string value to sbyte and store in sbyte[] array.In my code i am not use byte[] array . i want only for sbyte[] array.
Posted
Comments
CodeHawkz 3-May-11 8:00am    
Any specific reason that you want to use sbyte instead of byte?

It depends on the encoding you want the bytes to represent, but the ASCII version would be:
Imports System.Text
.
.
.
Dim chars As Byte() = Encoding.ASCII.GetBytes("Some string")

Read up on the System.Text.Encoding class and you'll find other encodings are supported, like UTF8, UTF32, Unicode, ... and alot of other methods that may be useful to you.
 
Share this answer
 
Comments
Olivier Levrey 3-May-11 8:01am    
OP asked for sbyte array and not byte array. But have a 5 anyway.
You can use Dave's answer to get the byte array and then convert to sbyte array using normal casts:
C#
//get the byte array
byte[] bytes = Encoding.ASCII.GetBytes("Some string");
//convert it to sbyte array
sbyte[] sbytes = new sbyte[bytes.Length];
for (int i = 0; i < bytes.Length; i++)
    sbytes[i] = (sbyte)bytes[i];
 
Share this answer
 
Comments
Ravi Sharma 2 7-May-11 10:25am    
Thanks this logic solved my problem
Go through the below link this may helps you

Here[^]
 
Share this answer
 

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