Removing one character from string
#1

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.
Reply
#2

Did you replace the @ by a space perhaps?

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

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

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 @ ?
Reply
#4

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


Maybe that counts as a space? I am not sure
Reply
#5

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.
Reply
#6

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?
Reply
#7

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, "@", " ");
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)