Author Topic: Modify word in sentence?  (Read 1185 times)

Lets say I have a sentence:

%words = "Happy flappy crappy"

And I wanna modify flappy to be trappy.

How would I go about doing this without doing this:
Code: [Select]
%words = getword(%words, 0) SPC "trappy" SPC getword(%words, 2);

Same goes for if the words were completely random and I wanted to change the center to trappy.

%words = setWord(%words,1,"trappy");

or for a random

%words= "Happy flappy crappy";

%random=getRandom(1,3) or instead of 3, you can use getwordcount(%words);

%replace=getWord(%words,%random);

%words=strReplace(%words,%replace,"Trappy");

this will change a random word, to trappy

Using strReplace would replace every occurance of %replace , if you just want to change that one you would do %words = setWord(%words,%random,"trappy");

but i dont see any other 'occurances' in the string

but yeah, setword would work better
« Last Edit: August 02, 2010, 07:57:33 PM by herb »

I'm pretty sure "Happy flappy crappy" was just an example.

Yeah it was.

Thanks so much! This has helped alot.

Why you are learning scripting while in some days you won't even have a tv?

Why you are learning scripting while in some days you won't even have a tv?
Because your mother.

Edit:

This is why americans suck at life. When they realize that they can't do something, they quit. I'm not a handicap like that. I keep going, so I won't end up being payed 7.50 an hour and living in my parents house.
« Last Edit: August 03, 2010, 08:48:56 AM by Pew446 »

How would I use this with variables?

Such as:

%var = "123 444 987";

setword(%var, 1, -= 10);

Or something?

How would I use this with variables?

Such as:

%var = "123 444 987";

setword(%var, 1, -= 10);

Or something?

what are you trying to do?

in words please

Code: [Select]
function switchWord(%text, %word, %replace) {
%r = 0;
for(%i = 0; %i < getWordcount(%text); %i++) {
if(getWord(%text, %i) $= %word) {
%text = setWord(%text, %i, %replace);
%r = 1;
}
}
return %r;
}

That should work. And I added a return if it changes any words.

what are you trying to do?

in words please

I want to do %var = %var - 10, but inside of the setword.

However this seems like a pain:

setword(%var, 1, (getword(%var, 1) - 10));

Code: [Select]
function switchWord(%text, %word, %replace) {
%r = 0;
for(%i = 0; %i < getWordcount(%text); %i++) {
if(getWord(%text, %i) $= %word) {
%text = setWord(%text, %i, %replace);
%r = 1;
}
}
return %r;
}

That should work. And I added a return if it changes any words.

Wouldn't that just be the same as setWord?

Wouldn't that just be the same as setWord?
switch, you dumbass.