PDA

View Full Version : First character - lower to Upper


Rolyy
10/08/2010, 02:24 PM
I want to make the first character of the first word to upper.
Something like a CAPS LOCK but then only for the first character of the first word.


3 Example:
I write this down: follow me
Message appears as: Follow me

I write this down: hacks OFF or ban!
Message appears as: Hacks OFF or ban!

I write this down: aaaaaaaaaaaaaaaa bbbbbb ccccccccccc
Message appears as: Aaaaaaaaaaaaaaaa bbbbbb ccccccccccc

ipsBruno
10/08/2010, 02:29 PM
In Final GameMode

forward UpperToLower(text[]);
public UpperToLower(text[])
{
for(new Char ; Char < strlen(text) ; Char++)
{
if(text[Char] > 64 && text[Char] < 91)
{
text[Char] += 32;
}
}
return 1;
}


Is OnPlayerText

UpperToLower(text);

Hiddos
10/08/2010, 02:31 PM
public OnPlayerText(playerid, text[])
{
if(text[0] >= 97 && text[0] <= 122) text[0]-=32;
return SendPlayerMessageToAll(playerid, text);
}


Edit to Drakon: For some weird reason lowerchase starts at 97, and upperchar at 65 :p

Rolyy
10/08/2010, 02:46 PM
Ugh sorry I didn't mention this, But its for a command..

if(text[0] == '&' && PlayerInfo[playerid][Level] >= 1) {
new string[128];
format(string,sizeof(string),"Admin: %s%s",string,text[1]); SendClientMessageToAll(green,string);
return 0;
}

ivex
10/08/2010, 04:05 PM
lool jus put under OnPlayerText

text[0] = toupper(text[0]);

That will make the first char of the text / string to upper so if you do let say :

Ivex say: dsadasdad nnnddd

it will be

Ivex say: Dsadasdad nnnddd

etc ... else if you do for other chats than you put insteed of "text" you put string or result or what ever you got :)

Rolyy
10/08/2010, 05:07 PM
Nope still fails =\

Y_Less
10/08/2010, 05:13 PM
Edit to Drakon: For some weird reason lowerchase starts at 97, and upperchar at 65 :p

It's not a wierd reason at all! Lower case a is character number 0x61 and upper case a is character 0x41' - it was designed this way to make case conversion faster - the only difference between the upper and lower case versions of a letter is bit 0x20. You can also use character constants instead of numbers to make your code more readable:


#define toupper(%0) \
(((%0) >= 'a' && (%0) <= 'z') ? ((%0) & ~0x20) : (%0))

#define tolower(%0) \
(((%0) >= 'A' && (%0) <= 'Z') ? ((%0) | 0x20) : (%0))

SlashPT
10/08/2010, 07:10 PM
im sure this one that y_less said it working... epic Y_Less win... XD

just need to put y_less code and onplayertext

text[0] = toupper(text[0]);

already tested... and works

EDIT: Y_Less please check your pm's

JaTochNietDan
10/08/2010, 07:51 PM
If you want to implement it in the specific command that you posted, it would look like this.


if(text[0] == '&' && PlayerInfo[playerid][Level] >= 1)
{
new string[128];
text[1] = toupper(text[1]);
format(string,sizeof(string),"Admin: %s",text[1]); SendClientMessageToAll(green,string);
return 0;
}


The other code didn't work because text[0] is not used at all in the string in your command.

SlashPT
10/08/2010, 09:56 PM
yep... anyways thanks ;)


@offtopic and JaTochNietDan please visit this http://forum.sa-mp.com/showthread.php?t=166896 no one tryng to help me... in a plugin

Bubelbub
15/07/2012, 06:49 PM
*DELETED* (where is delete function? -.-)