Portal SAMP
[Ajuda] como converter caracteres em brancos por "_"? - Versão de Impressão

+- Portal SAMP (https://portalsamp.com)
+-- Fórum: SA-MP (https://portalsamp.com/forumdisplay.php?fid=5)
+--- Fórum: Área de suporte (https://portalsamp.com/forumdisplay.php?fid=6)
+--- Tópico: [Ajuda] como converter caracteres em brancos por "_"? (/showthread.php?tid=1193)



como converter caracteres em brancos por "_"? - zBL4CK - 16/05/2021

eae pessoal blz?

bom eu estou fazendo um sistema de mensagem em textdraw bom por algum motivo o textdraw(quando crio pelo Nickk's textdraw editor) quando á um espaço em branco ele quebra a linha e para contornar isso basta usar um "_" bom se alguém souber uma para que espaços em branco não quebre a linha vai ser bom.

enfim eu tentei usar um sistema disponibilizado por um membro do forum:

Código PHP:
stock TextConverter(string[])
{
    for(new arraysize 0arraysize strlen(string); arraysize++)
    {
    if(
strfind(string" "true) != -1){new pos strfind(string" "true); strdel(stringpospos+strlen(" ")); strins(string"_"possizeof(pos));}
    }
    return 1;


eu adaptei porem não funciona alguém sabe uma forma de resolver isso?


RE: como converter caracteres em brancos por "_"? - Dr Editor - 17/05/2021

Este código além de feio é desotimizado.
Código PHP:
stock TextConverter(string[], nova_string[])
{
    for(new 0strlen(string); i++)
    {
        if(string[i] == ' ')
            string[i] = '_';
    }
    
    strcat
(nova_stringstringstrlen(string) + 1);
    return 1;




RE: como converter caracteres em brancos por "_"? - zBL4CK - 17/05/2021

(17/05/2021 09:41)Dr Editor Escreveu: Este código além de feio é desotimizado.
Código PHP:
stock TextConverter(string[], nova_string[])
{
    for(new 0strlen(string); i++)
    {
        if(string[i] == ' ')
            string[i] = '_';
    }
    
    strcat
(nova_stringstringstrlen(string) + 1);
    return 1;


muito obrigado!


RE: como converter caracteres em brancos por "_"? - OTAKEIRO - 18/05/2021

Include strlib tem o strreplace


RE: como converter caracteres em brancos por "_"? - Dr Editor - 19/05/2021

(18/05/2021 17:31)OTAKEIRO Escreveu: Include strlib tem o strreplace

Essa função executa instruções totalmente desnecessárias para a finalidade solicitada no post, mas sim, é uma alternativa.

Olha as instruções do bloco:
Código PHP:
stock strreplace(string[], const search[], const replacement[], bool:ignorecase falsepos 0limit = -1maxlength sizeof(string)) 
{
    if (limit == 0)
        return 0;
    
    
new
         sublen strlen(search),
         replen strlen(replacement),
    bool:packed ispacked(string),
         maxlen maxlength,
         len strlen(string),
         count 0;
    
    
if (packed)
        maxlen *= 4;
    
    
if (!sublen)
        return 0;
    
    
while (-!= (pos strfind(stringsearchignorecasepos))) 
    {
        strdel(stringpospos sublen);
        
        len 
-= sublen;
        if (replen && len replen maxlen
        {
            strins(stringreplacementposmaxlength);
            
            pos 
+= replen;
            len += replen;
        }
        
        
if (limit != -&& ++count >= limit)
            break;
    }
    
    
return count;




RE: como converter caracteres em brancos por "_"? - xbruno1000x - 19/05/2021

Tópico já foi resolvido... não há porque prolongar a discussão.