2019-06-14 08:49:44

Ok. So I've run into an annoying issue. Let's say I have the following

hi, I'm alive
I am hungry
give me something to eat

Let's say I want to remove the word alive from the first line, and I want to use the line separator as a reference point to begin trimming in bgt. Well I don't know how bgt is interpreting that line separator. I've tried \r, \n, and \c, but it doesn't recognize the line indicator. What will help it recognize it?

Do I need to make an array and have each line be an entry and tell bgt to paste each line in a for loop? Or is their a symbol I can use for multi-line variables.

2019-06-14 16:28:53

OK, so trimming and removing a word from a string are two different things. What do you really want to accomplish? Trimming seems to be rather inefficient here, because you'd need to re-join the entire string again.
How about just doing

text = string_replace(text, "alive", "", false);

instead?

There are of course more flexible ways possible using string_left and string_right, but I wouldn't use the trim methods to accomplish this task.
Best Regards.
Hijacker

2019-06-15 11:51:24

well ok. Here's what I am trying to accomplish here. This is part of the rhythm rage level creator project.
So let's say I have a file like this

name=sound1
fail=sound2
late=sound3

I want to change the sound for fail=. So I select my sound and make the name of the file without the ogg extension the variable name. Now I need to open the file and keep everything the same, except for the text after fail=. So I split the string where fail= is, and then the rest of that fail= line contains the text I want to replace, AKA the old sound file name with the new one. What is the best way to accomplish this?

2019-06-15 15:20:35

Line endings are CR ("\r"), LF ("\n"), or CRLF on windows ("\r\n")

The best way of handling this would be to split the string by both. As you might recall, the string_split function contains a boolian parameter that, when false, can include all or part of the delimiter. That way, in  the case of "\r\n", you'd be getting "\r", "\n", and obviously "\r\n" depending on which line endings are in use.

Note: this hasn't been tested, so you might have to do a bit of cleanup.

string[] line;
string[] content=string_split(f.read(), "\r\n", false);
for(uint i=0;i<content.length();i++)
{
line=string_split(i, "=", false);
if line[0]=="name")
{
//Do stuff, line[1] is the content.
}
if line[0]=="fail")
{
//do more stuff
}
}

2019-06-15 17:59:43

Ah, I see. I only had it split with “\n”