In fact I had a logfile, that I decoded, by reading his contents byte after byte and save it in a Byte Array. And there after I converted my array of byte in hexadecimal value, and Save it in a stringbuilder. But now my problem is the following, how to pass from the hexadecimal in the original values, because the normal values considering the text of origin before being coded in logfile contained values of type Integer, float, andstring. And I would like to know how i can make to obtain these values contained in my Stringbuilder and move it to the corresponding value in Integer,String or Float.

Thx in advance

Some possibilyties:

string hex = "F0000020";
int p = Convert.ToInt32(hex, 16);
int n = Int32.Parse(hex, System.Globalization.NumberStyles.HexNumber);

i have already dit it,but what about when i have a hex value who is big as 931 byte,and save in a Stringbuilder like:
F0000020F0000020F0000020F0000020F0000020F0000020F0000020F0000020F0000020F0000020F0000020F0000020F0000020F0000020F0000020F0000020F0000020F0000020F0000020F0000020F0000020F0000020F0000020F0000020F0000020F0000020F0000020F0000020F0000020F0000020.
thx

i have a question,how can i use the Methode Append for StringBuilder,with Stringbuiler Array,and does Stringbuilder have a equivalent of Substring Methode von string??? when yes which one???thx

Hey in my Code i have got a failure,may can somebody help me.i try in my function to convert byte value in Interger and character,but i got a failure,The object reference was not specified on an object instance. what i may supose do to???

Post some code were it goes wrong.
In answer to your previous post: both questions: no
but you can do this:

StringBuilder sb = new StringBuilder("test");
string s = sb.ToString();
s = s.Substring(1, 2);

s will now be equal to "es".

That is the function wo make me many trouble.thx in advance

private static String ByteToChar(byte[] source) 
        { 
          Char []CharString = new Char[source.Length];
          int []TempVal = new int[source.Length];
            for(int i = 0; i< source.Length; i++)
            {
                
                StringBuilder[] Temp = new StringBuilder[source.Length];
                Temp[i].Append(source[i].ToString("X2"));// that is the place wo make trouble
                String STR = Temp.ToString();
                MessageBox.Show(Temp[i].ToString());
                
                for (int j = 0; j <= source.Length; j+=4 )
                {
                    TempVal[i] = int.Parse(STR, System.Globalization.NumberStyles.HexNumber);
                    String Temp2 = (Temp[i].Append(source[i].ToString("X2"))).ToString();
                    MessageBox.Show("TempVal[i]", TempVal[i].ToString());
                    MessageBox.Show("STR", STR.ToString());
                    String Str = "";
                CharString[i] += (Char)Int16.Parse(Temp2.Substring(i, 4), NumberStyles.AllowHexSpecifier);
                MessageBox.Show(CharString[i].ToString());
                }
            
            }
            
            return CharString.ToString();
            
            
        }

From what you said in your earlier posts I don't think you want StringBuilder[] Temp = new StringBuilder[source.Length] which is an array of StringBuilders. Your line String STR = Temp.ToString(); I think would just return the name (type) of the object, an array of StringBuilders, not the string that you're actually trying to build.

I bet that's what causing your problem too, you're trying to append something to a specific StringBuilder object in your Temp array, but they haven't been initialized yet ( you haven't done Temp[i] = new StringBuilder(); for example).

Also, since your Temp declaration is inside your for loop it will be reinitialized every iteration of the loop.

You probably just want

//etc.
StringBuilder Temp = new StringBuilder();
for (int i = 0; i< source.Length; i++)
{
    Temp.Append(source[i].ToString("X2"));
    String STR = Temp.ToString();
    MessageBox.Show(Temp.ToString());
    // etc.
}

If you do want/need an array of StringBuidlers you'll still need to move the Temp declaration outside the for loop and initialize the individual StringBuilder objects before you Append to them.

Hope that helps!

Comments
Nice explanation.
This article has been dead for over six months. Start a new discussion instead.