SA-MP Forums Archive
Removing one character from 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)
+--- Thread: Removing one character from string (/showthread.php?tid=491188)



Removing one character from string - CH | FuDo - 29.01.2014

I want to when player type in dialog his email adress, to format it into a string and then to show it in textdraw without @. I tried with str_replace, but my textdraw show just this, for example:

typing: dirigent00@gmail.com
textdraw show this: irigent00 gmail.com

Any other ways to fix this? Thank you.


Re: Removing one character from string - PowerPC603 - 29.01.2014

Did you replace the @ by a space perhaps?

str_replace("@", "", YourEmail);

Should do it.
The second parameter is just an empty string: "".


Re: Removing one character from string - CH | FuDo - 30.01.2014

Quote:
Originally Posted by PowerPC603
Посмотреть сообщение
Did you replace the @ by a space perhaps?

str_replace("@", "", YourEmail);

Should do it.
The second parameter is just an empty string: "".
I have tried as you written, but now it look like this:

dirigent00gmail.com

Is there any chance to make space instead of @ ?


Re: Removing one character from string - thimo - 30.01.2014

str_replace("@", "_", YourEmail);


Maybe that counts as a space? I am not sure


Re: Removing one character from string - AlonzoTorres - 30.01.2014

Quote:
Originally Posted by PowerPC603
Посмотреть сообщение
Did you replace the @ by a space perhaps?

str_replace("@", "", YourEmail);

Should do it.
The second parameter is just an empty string: "".
The second parameter should be " " and not "", otherwise it's not a space. And no a underline does not count as a space.


Re: Removing one character from string - CH | FuDo - 30.01.2014

Quote:
Originally Posted by AlonzoTorres
Посмотреть сообщение
The second parameter should be " " and not "", otherwise it's not a space. And no a underline does not count as a space.
I tried as you said, but no, it's not working, I have wrote it in first post. It replace @ with space, but also remove the first character.

Any other help?


Re: Removing one character from string - ProjectMan - 30.01.2014

Use Slice's strreplace:

pawn Код:
stock strreplace(string[], const search[], const replacement[], bool:ignorecase = false, pos = 0, limit = -1, maxlength = sizeof(string)) {
    // No need to do anything if the limit is 0.
    if (limit == 0)
        return 0;
   
    new
             sublen = strlen(search),
             replen = strlen(replacement),
        bool:packed = ispacked(string),
             maxlen = maxlength,
             len = strlen(string),
             count = 0
    ;
   
   
    // "maxlen" holds the max string length (not to be confused with "maxlength", which holds the max. array size).
    // Since packed strings hold 4 characters per array slot, we multiply "maxlen" by 4.
    if (packed)
        maxlen *= 4;
   
    // If the length of the substring is 0, we have nothing to look for..
    if (!sublen)
        return 0;
   
    // In this line we both assign the return value from "strfind" to "pos" then check if it's -1.
    while (-1 != (pos = strfind(string, search, ignorecase, pos))) {
        // Delete the string we found
        strdel(string, pos, pos + sublen);
       
        len -= sublen;
       
        // If there's anything to put as replacement, insert it. Make sure there's enough room first.
        if (replen && len + replen < maxlen) {
            strins(string, replacement, pos, maxlength);
           
            pos += replen;
            len += replen;
        }
       
        // Is there a limit of number of replacements, if so, did we break it?
        if (limit != -1 && ++count >= limit)
            break;
    }
   
    return count;
}
pawn Код:
strreplace(YourEmail, "@", " ");