0

What I want to do is set the amount of characters BinaryReader.ReadString() reads to 1. I have this in a file

43 00 49 00 54 00 52 00 41 = C I t r a

obviously I can make it read C I t r a by just doing BinaryReader.ReadString() but instead what I want to do is remove the spaces between the letters and make it check to see if there are any letters after the a. This is what I have now

//OF_name is the offset at which the name begins at
//sins there is a space between each letter, I do "I += 2"
for (int i = OF_name; i <= br.BaseStream.Length; i += 2)
{
    br.BaseStream.Position = i;
    byte check = br.ReadByte();
    if (check == 0) break; //the file which contains the string always has a 7 byte space between the name bytes and the rest of the data.
    string a = br.ReadByte().ToString(); //forgot that this just makes it be represented as a string (byte 43 => string "43" not "C")
}

Is there a way to make ReadString() read 1 character at a time instead of 7 so it would read C then I then t and so on? or is there a way to do it as I do but instead of converting byte 43 to string "43" it would convert byte 43 to string "C"?

Gecko45444
  • 73
  • 1
  • 1
  • 6
  • Read the number of _bytes_ you need, then pass that to an Encoding of choice. You probably have to read an even amount, or append another 0 byte, then decode using UTF-16 (`Encoding.Unicode.GetString(bytes)`). – CodeCaster Sep 30 '17 at 23:51
  • 1
    Those are not spaces. You need to [read a string in little-endian UTF-16 encoding with BinaryReader](https://stackoverflow.com/questions/25082280/). – Dour High Arch Oct 01 '17 at 00:02

0 Answers0