4

I need to convert a byte [] to string in C# and Unity without losing much of a Frame Per Second. I'm currently using the WWW class to fetch the text file, but when I use WWW.text, as the file is too large and causes a drop in FPS. Is there any way to make the conversion incrementally, without delay too long.

WWW file = new WWW(path);
yield return file;
string text= file.text;

I use this to read an full file(one .OBJ) and i need to read all text. Line to line or all text to one string to split after. To read text without drop in FPS, i make this.

WWW file = new WWW(path);
yield return file;
string text= file.bytes;

if file are to much big, WWW.text, drop FPS, then i need use WWW.bites. In Unity useyield return null; to process another frame. If process need too much time to execute then drop FPS(in case WWW.text);

2
  • 1
    Voting to reopen as it looks like question is about consuming portions of the byte array as string rather than "how to convert whole array to string"... user3541917 - could you please clarify the problem and show how you use resulting string. If you need content as single string it is indeed duplicate question, but if you want to consume parts of the string it is different question. Than is should be reworded/asked again to show how you want to consume results of "conversion incrementally". Commented Apr 16, 2014 at 16:29
  • I agree with Alexei's point. This isn't a straight conversion question. Rather, it's a technique question for managing fps and doing the conversion without impacting the rest of the application. Commented Apr 16, 2014 at 16:47

1 Answer 1

2

I never used Unity but try this: String str = System.Text.Encoding.Default.GetString(result);

3
  • 4
    That is not how one converts a byte[] to a meaningful string Commented Apr 16, 2014 at 16:04
  • Encoding class does this job. I'd add that a string can be encoded differently, so you OP can use Unicode, UTF-8 etc. Otherwise this is a good start.
    – oleksii
    Commented Apr 16, 2014 at 16:06
  • This convert all byte[] in one time and causes a drop in FPS. I use WWW.bytes because is more quick and not drop FPS. Need convert to string in incremental times. WWW file = new WWW(path); yield return file; string text= file.text; Commented Apr 17, 2014 at 9:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.