09/12/2020 14:46
Conversor de caracteres de texto: maiúsculas, minúsculas, intercala, inverte e converte para maiúscula a primeira letra de cada palavra.
Código:
enum
{
TO_LOWER,
TO_UPPER,
INTERCALATE,
INVERT,
UPPER_FIRST_CHAR
}
stock ChangeStringCase(input_text[], output_text[], case_type)
{
new count = 0;
if(case_type == TO_LOWER)
{
while(count < strlen(input_text))
{
new _char[2];
format(_char, 2, "%c", tolower(input_text[count]));
strcat(output_text, _char, strlen(input_text) + 1);
count ++;
}
}
else if(case_type == TO_UPPER)
{
while(count < strlen(input_text))
{
new _char[2];
format(_char, 2, "%c", toupper(input_text[count]));
strcat(output_text, _char, strlen(input_text) + 1);
count ++;
}
}
else if(case_type == INTERCALATE)
{
new bool:intercalate = true;
while(count < strlen(input_text))
{
new _char[2];
format(_char, 2, "%c", intercalate ? toupper(input_text[count]) : tolower(input_text[count]));
strcat(output_text, _char, strlen(input_text) + 1);
intercalate = !intercalate;
count ++;
}
}
else if(case_type == INVERT)
{
while(count < strlen(input_text))
{
new _char[2];
switch(input_text[count])
{
case 'a'..'z':
{
format(_char, 2, "%c", toupper(input_text[count]));
strcat(output_text, _char, strlen(input_text) + 1);
}
case 'A'..'Z':
{
format(_char, 2, "%c", tolower(input_text[count]));
strcat(output_text, _char, strlen(input_text) + 1);
}
default:
{
format(_char, 2, "%c", input_text[count]);
strcat(output_text, _char, strlen(input_text) + 1);
}
}
count ++;
}
}
else if(case_type == UPPER_FIRST_CHAR)
{
new bool:upper = false;
while(count < strlen(input_text))
{
new _char[2];
switch(input_text[count])
{
case 'a'..'z', 'A'..'Z':
{
if(upper)
{
format(_char, 2, "%c", toupper(input_text[count]));
strcat(output_text, _char, strlen(input_text) + 1);
upper = false;
}
else
{
format(_char, 2, "%c", input_text[count]);
strcat(output_text, _char, strlen(input_text) + 1);
}
}
default:
{
format(_char, 2, "%c", input_text[count]);
strcat(output_text, _char, strlen(input_text) + 1);
upper = true;
}
}
count ++;
}
}
}
SA:MP Dev Tools
Faça mais, ganhe mais e poupe tempo!
Viper Anti-Cheat
Torne seu servidor mais seguro!
________________________________________
Soluções personalizadas para SA:MP
Discord: .eduardoac | Eduardo AC#3140
Faça mais, ganhe mais e poupe tempo!
Viper Anti-Cheat
Torne seu servidor mais seguro!
________________________________________
Soluções personalizadas para SA:MP
Discord: .eduardoac | Eduardo AC#3140