SA-MP Forums Archive
Text in string. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Text in string. (/showthread.php?tid=154292)



Text in string. - Logitech334 - 13.06.2010

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?


Re: Text in string. - TheInnocentOne - 13.06.2010

Text has to be in a string...


Re: Text in string. - Logitech334 - 13.06.2010

@up

lol, i know and it is -.-


Re: Text in string. - Cameltoe - 13.06.2010

If you post your script more scripters could help you out


Re: Text in string. - Logitech334 - 13.06.2010

@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.


Re: Text in string. - Dark_Kostas - 13.06.2010

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.


Re: Text in string. - Logitech334 - 13.06.2010

Код:
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..


Re: Text in string. - Dark_Kostas - 13.06.2010

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


Re: Text in string. - Nero_3D - 13.06.2010

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;
}



Re: Text in string. - Logitech334 - 13.06.2010

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