[SNIPPET] Get digits from text

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:

Parazitas

God
Joined
Jan 2, 2017
Messages
3,103
Solutions
5
Reaction score
882
Location
Lithuania
PHP:
:CollectAllDigits
{
    0AB1: @CollectAllDigits 1 stringPointer 1@
    Self Return: 1@ - Digits
}
0C17: 31@ = strlen 0@
31@ -= 1
0085: 28@ = 0@
005A: 28@ += 31@
0085: 27@ = 0@
for 30@ = 0@ to 28@
0A8D: 29@ = read_memory 30@ size 1 virtual_protect 1
    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
        0A8C: write_memory 27@ size 1 value 29@ virtual_protect 1
        27@++ //27@ increases only if it's a digit
    else
        // do nothing...
    end    
end
0A8C: write_memory 27@ size 1 value 0 virtual_protect 1
0AB2: ret 0
 
Last edited:

Parazitas

God
Joined
Jan 2, 2017
Messages
3,103
Solutions
5
Reaction score
882
Location
Lithuania
Improvement:
1. Removed strlen snippet requirement

2. Removing any existing color code and returning only digits

PHP:
:get_digits_to_print
{
    0AC8: 1@ = allocate_memory_size 1024
    0AB1: @get_digits_to_print 2 text 0@ memory_to_store_digits_as_text 1@
}
5@ = FALSE // inbracket
0AA7: call_function 0x718690 num_params 1 pop 1 string 0@ _Returned: length 31@ // Gta Strlen
    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 28@ == 123
        THEN 5@ = TRUE // inbracket
        END
        
        IF 5@ == FALSE
        THEN
            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
        
        IF 28@ == 125
        THEN 5@ = FALSE // inbracket
        END
    END
0A8C: write_memory 1@ size 1 value 0 virtual_protect 1 // null-termination
0AB2: ret 0
 
Last edited:

Davidthapa

Active member
Joined
Mar 20, 2017
Messages
32
Reaction score
1
Location
Shillong, Meghalaya, India
User has been warned.
i need exact digit number as integer
how to do it look example below
while true
wait 5
//example
call @Reset 0
0AC8: 0@ = allocate_memory_size 1000
0AC8: 1@ = allocate_memory_size 2000
0AD3: 0@ = format "1000" //i need this number value
0AD3: 1@ = format "%s" 0@ //your script which is string
//now if i read with
0ad1: "as string %s but i need that digits in integer %i" 2200 1@ 1@
//more example i want thoes digits from string to precise value in integer
045A: draw_text_1number 320.0 224.0 GXT 'NUMBER' number 1@
0342: enable_text_draw_centered 1
03F0: enable_text_draw 0
free 0@
free 1@
end
 

Parazitas

God
Joined
Jan 2, 2017
Messages
3,103
Solutions
5
Reaction score
882
Location
Lithuania
i need exact digit number as integer
how to do it look example below
while true
wait 5
//example
call @Reset 0
0AC8: 0@ = allocate_memory_size 1000
0AC8: 1@ = allocate_memory_size 2000
0AD3: 0@ = format "1000" //i need this number value
0AD3: 1@ = format "%s" 0@ //your script which is string
//now if i read with
0ad1: "as string %s but i need that digits in integer %i" 2200 1@ 1@
//more example i want thoes digits from string to precise value in integer
045A: draw_text_1number 320.0 224.0 GXT 'NUMBER' number 1@
0342: enable_text_draw_centered 1
03F0: enable_text_draw 0
free 0@
free 1@
end
Hi,

1. Wrong section to ask about
2. You should explain more clearly...

Regards,
Parazitas.
 
Top