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);

user3541917
  • 61
  • 1
  • 6
  • 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". – Alexei Levenkov Apr 16 '14 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. – C4 - Travis Apr 16 '14 at 16:47

1 Answers1

2

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

Over Killer
  • 507
  • 9
  • 24
  • 4
    That is not how one converts a `byte[]` to a meaningful `string` – Marc Gravell Apr 16 '14 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 Apr 16 '14 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;` – user3541917 Apr 17 '14 at 09:34