ID:157685
 
I haven't worked with byond in a while so I have forgotten some of the built-in procs or whatever.

And I can't look them up because for some reason the dm reference is bugged in v462.

So, lets say I have a text string var/Text="I crapped myself".

But I want to change the word "crapped" to "OLIOLIOLIOOOO"...How would I do that?
Dragonn wrote:
And I can't look them up because for some reason the dm reference is bugged in v462.

-There is an online reference.
-You should report any bugs to the bug tracker.

But I want to change the word "crapped" to "OLIOLIOLIOOOO"...How would I do that?

You'd search for where the phrase you want to replace is using findtext(). Then, you'd "split" the string into 2 parts (using copytext()): the part before the phrase's position, and the part after it - while putting the new phrase in the middle:
new_text = text_before_phrase + new_phrase + text_after_phrase

You can look at various libraries' implementation of replacetext() for full examples.
In response to Kaioken
Ok that all makes sense, except one thing. How do I detect how many characters there are leading up to the word I want to replace? And how many characters remaining past the word I want to replace (if necessary)? I'm under the impression that I need to know that if I want to cut the text before and after the word I want to replace

Or is that not the right way?
In response to Dragonn
Dragonn wrote:
How do I detect how many characters there are leading up to the word I want to replace?

findtext()

And how many characters remaining past the word I want to replace (if necessary)?

You don't have to know that, since copytext() will copy to the end of the string by default. You do need to know at which point the phrase you're replacing ends, which is why you'd calculate its length().
In response to Kaioken
I looked in the library section, the terms "replace text" and "replacetext" returned no results.

I looked in the DM reference and findtext() only returns a 1/true or 0/false so I don't get what you telling me about that.

Can you show me a working example of replacing a word in a text string? All these tidbits of information aren't letting me see the big picture so far...

When I implement it there will be specific words I want to replace. Lets say the word I want to replace is "bean", and I want to replace it with "waffle"

Thanks
In response to Dragonn
Dragonn wrote:
I looked in the library section, the terms "replace text" and "replacetext" returned no results.

Well, the search doesn't scan the library itself, only the hub descriptions, which doesn't necessarily contain the proc names (which could be anything, while we're on that). So refine your search accordingly.
Other things you can try are searching the Dream Makers forum (this one), the Dream Makers guild and Jt's Snippets Database.

I looked in the DM reference and findtext() only returns a 1/true or 0/false

No.

Can you show me a working example of replacing a word in a text string? All these tidbits of information aren't letting me see the big picture so far...

I'd rather have you learn from arriving at the solution on your own.
In response to Dragonn
Dragonn wrote:
I looked in the DM reference and findtext() only returns a 1/true or 0/false so I don't get what you telling me about that.

I'm not sure where you looked, but findtext returns 'The position of Needle in Haystack; 0 if not found.'
In response to Kaioken
Ok then. Thanks. I'll check elsewhere.
In response to Schnitzelnagler
This is what I looked at: http://www.byond.com/members/?command=reference&path=proc/ findtext

It seemed very vague to me. It's not the same link in your post. But don't worry about it I found a library called TextHandling or something that SEEMS to solve it. (I haven't actually tested out the procs)
In response to Dragonn
Dragonn wrote:
This is what I looked at: http://www.byond.com/members/?command=reference&path=proc/ findtext

It seemed very vague to me. It's not the same link in your post. But don't worry about it I found a library called TextHandling or something that SEEMS to solve it. (I haven't actually tested out the procs)

Format:
findtext(Haystack,Needle,Start=1,End=0)

Returns:
The position of Needle in Haystack; 0 if not found.

The references are the same, Snalger was pointing to the old single page reference, you're pointing to the new reference.

There is nothing vague about that. A lot of programming references refer to the "text to search" as a haystack and what you're trying to find as a "needle". It plays on the saying "trying to find a needle in a haystack". You have to actually read the reference entry, not look at the example and make assumptions based off that.