string cut
#1

hi, i have this code:
pawn Код:
new
                msg[ 128 ];
            format( msg, 128, "%s", inputtext );
            InfoMSG( playerid, msg );
and it's retrieves all string, like
Quote:

Ance_Zas: Prisijunges

I need to cut : Prisijunges, I would use strmid but the Ance_Zas is player name, and it's featced from mysql, its not static and every time can be difrent leitgh. any ideas?
or mabye i can retrieve the player name from dialog to listitem easyest way?
Reply
#2

Can you try be abit more specific so I could help you more?
Reply
#3

pawn Код:
strdel(msg, 0, strfind(msg, ":") + 1); //this will return 'Prisijunges'
strdel(msg, strfind(msg, ":") + 1, strlen(msg)); //this will return 'Ance_Zas'
Reply
#4

pawn Код:
new msg[21], pos = strfind(inputtext, ":"), length = strlen(inputtext);
if (pos != -1)
{
    strmid(msg, inputtext, pos, length, 21);
    InfoMSG(playerid, msg);
}
Reply
#5

if( dialogid == 312 )//Darbuotju valdymas...
{
if( response )
{
new msg[21], pos = strfind(inputtext, "-"), length = strlen(inputtext);
strmid(msg, inputtext, pos, length, 21);
InfoMSG(playerid, msg);
}
return true;
}

it gives "- prisijunges" that it deletes that string that should be left its all reverse, so how to do it ritgh?
Reply
#6

Oh, that was a mistake by my side. Change to:
pawn Код:
new msg[21], pos = strfind(inputtext, ":");
if (pos != -1)
{
    strmid(msg, inputtext, 0, pos, 21);
    InfoMSG(playerid, msg);
}
Reply
#7

new
msg[ 21 ],
pos = strfind( inputtext, " -" );
strmid( msg, inputtext, 0, pos, 21 );
InfoMSG( playerid, msg );
new name = strval( msg );
and the verible name is return zero, why?
Reply
#8

The example you gave is: "Ance_Zas: Prisijunges". The code I wrote will return "Ance_Zas" but you search for " -" and you never check if it was found or not. In case " -" doesn't exist in the inputtext, the length will be 0 and msg will not hold the name.
Reply
#9

so how to do that msg hold palyer name?
Reply
#10

Read what I said above, it all depends on you. The inputtext has after the name ":" or " -" character? Replace strfind with the character your inputtext holds after the name.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)