Issue with recursion and replacements
#1

Essentially, what I'm trying to do is search an input string and find the closest space nearest to the end of the string. From that point I then want to insert '...' and put the rest of the text onto the next line, preceded by '...'.

Could anyone explain (any) of this to me? I've made some headway, but I need some help with finding the space in the string. I think then I might be able to work out how to put the elipses where I need them.

Many thanks.
Reply
#2

Well first to get the string input you should use sscanf and zcmd:
pawn Код:
CMD:somecommand(playerid, params[])
{
new string[128];
if(sscanf(params, "s", string)) return SendClientMessage(playerid, -1, "You must enter a string!");

....
}
Then, to find the last space you need to use strfind, which returns the location of the found substring in the main string:
pawn Код:
new offset = 0, actualOffset = 0;
for(new i = 0; i < sizeof string; i++)
{
   actualOffset = offset;
   offset = strfind(string, " ", true, actualOffset);
   if(offset == -1) break; //This means no space was found.
} //If it goes out of the loop we found the last space location.
Now we can use strmid to extract what's after the space to string2: (https://sampwiki.blast.hk/wiki/Strmid)
pawn Код:
strmid(string2,string,offset,sizeof string) // we cut whatever that is from the last space to the end of the string and paste it to string2
Now you want to insert '...' in the first string so you do that by using strins:
pawn Код:
strins(string, "...", offset)
Then you can send both of these messages to whoever you want.. Hope this helps!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)