Text in string.
#1

Hey Guys again

I have problem. I want make function which would change text in string.
eg. I have text "lol lol lol lol lol lol lol lol lol lol lol lol lol" in string. Now i want detect every fifth space and replace it on "cos".
eg. "lol lol lol lol lolcoslol lol lol lol lolcoslol". My friend from polish helped me a little bit, but it is not yet.



How do it?
Reply
#2

Text has to be in a string...
Reply
#3

@up

lol, i know and it is -.-
Reply
#4

If you post your script more scripters could help you out
Reply
#5

@up Yep... but this is not mutch.. ok

Код:
stock SpaceChange(text[])
{
	new len=strlen(text);
 	new c;
 	for(new i=0;i<len;i++)
  {
	  if(text[i] == ' ')
  	  {
	    
		}
	}
	return text;
}
And next I do not know what to do.
Reply
#6

pawn Код:
stock SpaceChange(text[])
{
    new modifiedstring[128];
    new len=strlen(text);
    new spacesfound;
    for(new i=0;i<len;i++)
    {
        if(spacesfound == 5)
        {
            spacesfound = 0;
            format(modifiedstring, sizeof(modifiedstring), "%scos", modifiedstring);
        }
        if(text[i] == ' ')
        {
            spacesfound++;
        }
        format(modifiedstring, sizeof(modifiedstring), "%s%s", modifiedstring, text[i]);
    }
    return modifiedstring;
}
Untested but should work.
Reply
#7

Код:
stock SpaceChange(const text[])
{
	new modifiedstring[300];
	new len=strlen(text);
	if (len==0) return false;
 	new spacesfound = 0;
	for(new i=0;i<len;i++)
	{
		if(spacesfound == 5 || spacesfound == 10 || spacesfound == 15 || spacesfound == 20 || spacesfound == 25 || spacesfound == 30)
		{
			len = len+3;
			format(modifiedstring, sizeof(modifiedstring), "%slol", modifiedstring);
		}
		if(text[i] == ' ')
		{
			spacesfound++;
		}
		format(modifiedstring, sizeof(modifiedstring), "%s%s", modifiedstring, text[i]);
	}
	Console::Output("%s", modifiedstring);
	return modifiedstring;
}
I modified to this.. My code & you code does not work..

Eg.. i use SpaceChange("Test") & returned "Testeststt". I know, i dont make 5 space but i test it..
Reply
#8

It shouldnt work, testing it now...
forget this way, im trying to find another
Reply
#9

if you change variables dont add const before it ^^"

pawn Код:
stock SpaceChange(text[], size = sizeof text)
{
    if (text[0] != EOS)
    {
        for(new i, c; text[i] != EOS; i++)
            if(text[i] == ' ')
                if((++c) == 5)
                {
                    text[i] = 'c'; //the first letter
                    strins(text, "os", (i + 1), size);
                    c = 0;
                }
        Console::Output("%s", text); //whats that :S
    }
    return text;
}
Reply
#10

Thanks Joker & Dark_Kostas.

Joker, thanks for teach me.

Btw, Console::Output this is my macro, i like this becouse is simple, i do not know & use print or prinf, this is on my one macro ) I like this xD
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)