Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Replace String Function

Author
Message
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 15th Jan 2013 01:55 Edited at: 15th Jan 2013 14:10
[edit: 15 JAN 13:10]
Fixed function from editing the source$ after only partial success, now returns unedited source$ unless complete success.
Changed the "*" to "~" so that search and replace strings can include "*". Not a great solution but there's no reason to use "~" in DBC so it should be adequate.
[/edit]

I wanted to do some complex string replacement in one of my programs. The problem is I have an array ship#(x,15) that I want to get rid of but "x" is a different variable all over the place!
So I wrote this function that can take "~" as a search parameter that tells the function to include everything between the two terms either side of "~".
It should be useful for some people.


Shh... you're pretty.
Fluffy Rabbit
User Banned
Posted: 15th Jan 2013 03:43
Cool, a string replace function, a lot like JavaScript's regex replace. I'm not sure how this relates to the array you mentioned, but this will certainly be useful to people with string-heavy programs. Here's a string split function that I wrote about a year ago for use in Dark Survival 2:

Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 15th Jan 2013 14:12
I've updated the original post with some fixes.
I couldn't get your function to work. I've probably mangled it beyond recognition but here's what I did with it:

Do you have an example of how it should work without editing?

Shh... you're pretty.
Fluffy Rabbit
User Banned
Posted: 15th Jan 2013 19:35
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 15th Jan 2013 21:51
Ah I see. That's a good setup for recursion:


Shh... you're pretty.
Fluffy Rabbit
User Banned
Posted: 15th Jan 2013 22:32
Wow, yours is twice as fast as mine. How does recursion make it faster, though? Couldn't that functionality be emulated? It makes for bad code, if you ask me. Nonetheless, it is faster:

Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 15th Jan 2013 22:51
I don't understand but it is now the same speed:

Changing to a for loop made 4 or 5 fps difference but it was taking out the s$ that caused a big jump. I don't know why one string would hurt performance so bad!

Shh... you're pretty.
Fluffy Rabbit
User Banned
Posted: 15th Jan 2013 23:58
Wow, that is faster. You are using a slightly different test, though. Still, I think you improved my function. Nice. I suppose I should try to implement it into DS2 to see if it improves load times, but I'm feeling pretty lazy right now. By the way, how is your space game coming along? Have you figured out how to use my music code?
Silverman
17
Years of Service
User Offline
Joined: 18th Jan 2007
Location: France
Posted: 16th Jan 2013 14:51
hey, i already make split function by the past
this is my(old) function:


enjoy!

DirectX 9.0c (February 2010)/ DBClassic v1.20
Fluffy Rabbit
User Banned
Posted: 17th Jan 2013 02:41
@Silverman-

I think we have a winner! Your algorithm is way faster than mine and doesn't depend on recursion.

Login to post a reply

Server time is: 2024-03-29 00:58:12
Your offset time is: 2024-03-29 00:58:12