Avoiding String "overload"
Author |
Message |
Verikyo
|
Posted: Sat Jun 27, 2009 6:49 pm Post subject: Avoiding String "overload" |
|
|
What is it you are trying to achieve?
I am trying to load lines of text from a file into a variable.
What is the problem you are having?
In some cases, the line is over the limit that a string can hold (255 characters). Is there a way to simply ignore the line and keep going without crashing?
The file also has ~15000 lines of text...
Please specify what version of Turing you are using
4.1.1 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Kharybdis
|
Posted: Sat Jun 27, 2009 7:13 pm Post subject: RE:Avoiding String "overload" |
|
|
well.. find how big the max line can hold in terms of characters.
once you have that count, use an array of string variables and when each string variable has reached its limit, get the rest of the line from the next variable in the array.
i hope that made sense. This is how i would do it without having to think much.
EDIT: and no, you can't really ignore the limit if the line has more than 255 characters. Each variable can only hold 255 characters, no more. Thus, the solution would be to make another temporary variable. |
|
|
|
|
|
andrew.
|
Posted: Sat Jun 27, 2009 7:17 pm Post subject: RE:Avoiding String "overload" |
|
|
There is no way around this. You can create an array of char and load each character of the file into there. That way you can make a lot of chars, but it still may not be big enough. In that case, you may want to try DemonWasp's string class. It is very similar to Java's String class. You can find it here. |
|
|
|
|
|
Verikyo
|
Posted: Sat Jun 27, 2009 7:34 pm Post subject: Re: Avoiding String "overload" |
|
|
thanks, i'll take a look at it. I was just wondering if there was a fairly simple way to do something like....get line, if line is over 255 characters, get next line.
EDIT:
get : fileID, input : *
that gets the whole line, but crashes if it goes over. I don't need the entire line, most of the info is within the first 255, but when i was testing:
get : fileID, input : (255)
put input
it would create an extra space between the lines. The output would turn from:
hello
world
to
hello
world.
Not sure if that was a problem, so i tried to think of a better solution |
|
|
|
|
|
|
|