sscanf checking string help -
Riwerry - 28.01.2014
Hello guys, is possible to edit this:
pawn Код:
if(sscanf(inputtext, "{p<_>s[9]s[9]}"))
{
SendClientMessage(playerid, -1, "You have entered wrong format of name!");
}
this checking if is the underscore in inputtext format NAME_LASTNAME it works pretty well but one thing, which doesnt work is: when I enter to inputtext this "_sometext" it says so it is correct, I just need to know I guess, how to get strlen of the string first tring and add if statement if is strlen bigger than 1.. Any ideas? thx
Re: sscanf checking string help -
Riwerry - 28.01.2014
Hm, I still got one problem.. When I type to inputtext as first character the underscore (_) it will detect him.. But when I type after underscore some text (string) like _world it will still detect it as correct..
Adding code
pawn Код:
case 7:
{
if (response)
{
if(sscanf(inputtext, "{p<_>s[9]s[9]}"))
{
new TEXT[MAX_PLAYER_NAME], underscorecount;
format (TEXT, sizeof (TEXT), "%s", inputtext);
for (new i; i < MAX_PLAYER_NAME; i++)
{
if (TEXT[i] == '_')
underscorecount++;
}
if (underscorecount > 1)
{
SendClientMessage (playerid, -1, "two underscores found!");
}
if (TEXT[0] == '_')
{
SendClientMessage(playerid, -1, "underscore is located in first place in inputtext!");
return ShowPlayerDialog (playerid, 3, DIALOG_STYLE_LIST, "Sprбvca postбv", "Načнtavanie postбv\nVytvorenie postбv\nVymazanie Postбv", "Potvrdiť", "Zruљiť");
}
SendClientMessage(playerid, -1, "You have entered bad format of name!");
return ShowPlayerDialog (playerid, 3, DIALOG_STYLE_LIST, "Sprбvca postбv", "Načнtavanie postбv\nVytvorenie postбv\nVymazanie Postбv", "Potvrdiť", "Zruљiť");
}
else
{
SendClientMessage(playerid, -1, "Correct format");
ShowPlayerDialog (playerid, 3, DIALOG_STYLE_LIST, "Sprбvca postбv", "Načнtavanie postбv\nVytvorenie postбv\nVymazanie Postбv", "Potvrdiť", "Zruљiť");
}
}
Dont worry about dialog lang
I translated messages / other stuff..
Re: sscanf checking string help -
Konstantinos - 28.01.2014
pawn Код:
stock isValidName(const sz_Name[])
{
new
lenght = strlen(sz_Name);
if (!lenght) return 0;
new
us_count;
for (new i; i != lenght; ++i)
{
if (sz_Name[i] == '_') ++us_count;
}
return (us_count == 1 && sz_Name[0] != '_' && sz_Name[lenght - 1] != '_');
}
You can use it:
pawn Код:
if (!isValidName(inputtext))
{
SendClientMessage(playerid, -1, "You have entered bad format of name!");
return ShowPlayerDialog (playerid, 3, DIALOG_STYLE_LIST, "Sprбvca postбv", "Načнtavanie postбv\nVytvorenie postбv\nVymazanie Postбv", "Potvrdiť", "Zruљiť");
}
else
{
SendClientMessage(playerid, -1, "Correct format");
ShowPlayerDialog (playerid, 3, DIALOG_STYLE_LIST, "Sprбvca postбv", "Načнtavanie postбv\nVytvorenie postбv\nVymazanie Postбv", "Potvrdiť", "Zruљiť");
}