With this snippet you can get digits from any text !
Explain.:
Code:
{$CLEO}
0000:
repeat
wait 50
until 0AFA: is_samp_available
0AC8: 0@ = allocate_memory_size 260
0AD3: 0@ = format "aaa:12345678910"
0AC8: 1@ = allocate_memory_size 260
0AB1: call_scm_func @get_digits_to_print param_count 2 text 0@ memory_to_store_digits_as_text 1@
chatmsg 1@ -1
0A93: end_custom_thread
:get_digits_to_print
{
0@ = text
1@ = pointer to memory where digits will be stored as text
}
0C17: 31@ = strlen 0@
for 30@ = 0 to 31@
0085: 29@ = 0@ // copy pointer
005A: 29@ += 30@ // add offset (as the loop progresses it becomes pointers to first-last character)
0A8D: 28@ = read_memory 29@ size 1 virtual_protect 1 // 28@ is the ascii number representing character
if and
28@ >= 0x30 // '0'
28@ <= 0x39 // '9'
then
0A8C: write_memory 1@ size 1 value 28@ virtual_protect 1
1@ += 1 // move to next address
end
end
0A8C: write_memory 1@ size 1 value 0 virtual_protect 1 // null-termination
0AB2: ret 0
Snippets.:
Code:
:get_digits_to_print
{
0@ = text
1@ = pointer to memory where digits will be stored as text
}
0C17: 31@ = strlen 0@
for 30@ = 0 to 31@
0085: 29@ = 0@ // copy pointer
005A: 29@ += 30@ // add offset (as the loop progresses it becomes pointers to first-last character)
0A8D: 28@ = read_memory 29@ size 1 virtual_protect 1 // 28@ is the ascii number representing character
if and
28@ >= 0x30 // '0'
28@ <= 0x39 // '9'
then
0A8C: write_memory 1@ size 1 value 28@ virtual_protect 1
1@ += 1 // move to next address
end
end
0A8C: write_memory 1@ size 1 value 0 virtual_protect 1 // null-termination
0AB2: ret 0
Code:
:Get3DigitsFromString
{
0AB1: @Get3DigitsFromString 1 stringPointer 0@ _returnedDigits 21@ 22@ 23@
}
0AC7: 20@ = var 21@ offset // 20@ will store pointer to variable 21@, so then we can add 4 to it and store values in: 21@ 22@ 23@ in a compact way
18@ = 0 //"safety" counter, to prevent checking for more than 3 numbers (otherwise variables like 30@ could be overwritten and it could mess the loop)
0C17: 31@ = strlen 0@
31@ -= 1
for 30@ = 0 to 31@ //for each char/byte in string
0A8D: 29@ = read_memory 0@ size 1 virtual_protect 1 //read the character and store it's ascii value to 29@
if and // if is equal or higher than "0" in ascii, and if is equal or lower than "9" in ascii (http://www.asciitable.com/index/asciifull.gif)
0029: 29@ >= 48
002B: 57 >= 29@
then
29@ -= 48 // now 29@ will contain the actual number, not ascii representation of it (48 will become 0, 49 will become 1)
0A8C: write_memory 20@ size 4 value 29@ virtual_protect 1
20@ += 4 // from now 20@ will point to the next variable (21@ -> 22@ -> 23@)
18@++
if 18@ > 3
then
ret 3 21@ 22@ 23@
end
end
0@++ //proceeding to the next char
end
ret 3 21@ 22@ 23@
Credits.:
@monday
Lithuanian letters in ascii table
Code:
224 - 254
Last edited: