Jump to content
Hostul a fost schimbat. Daca vedeti serverul offline readaugati rpg.b-zone.ro sau 141.95.124.78:7777 in clientul de sa-mp ×

[CLEO] Get only first/last X characters of a string


Moderat
 Share

Recommended Posts

Hello,

 

Would it be possible in CLEO to get the first or last 20 characters from a string, for example?

 

I want to implement a function in a script that if I write something which has more than 99 characters, then the additional characters will be sent as a second message automatically.

 

I have no idea where to start with this particular section of code, so there's nothing already made for now. I know the CLEO language enough to implement it in my script afterwards.

Edited by Moderat
Link to comment
Share on other sites

Hello, 

 

 

Snippets:

:GetFirstCaractersFromString
0C24: strncpy destination 0@ source 0@ size 1@
0AB2: ret 1 0@
:GetLastCharactersFromString
0C17: 2@ = strlen 0@
0062: 2@ -= 1@
005A: 0@ += 2@
0AB2: ret 1 0@  

 

Exemple for usage:

:Ex
alloc 30@ 128
format 30@ "SunnyBuilder" // your test string

chatmsg "Original String: %s" -1 30@
alloc 31@ 128 // allocate memory for new string (caracters)
0AB1: @GetFirstCaractersFromString 2 from_string 30@ caracters 5 _returnedCaracters 31@
chatmsg "First 5 caracters from string: %s" -1 31@ // new string will be "Sunny"
free 31@

alloc 31@ 128 // allocate memory for new string (caracters)
0AB1: @GetLastCharactersFromString 2 from_string 30@ characters 5 _returnedCaracters 31@
chatmsg "Last 5 caracters from string: %s" -1 31@ // new string will be "ilder"
free 31@

free 30@ // free memory from your test string
SAMP.CmdRet

 

Edited by Tupi
Link to comment
Share on other sites

  • Nic locked this topic
Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.