CLEO Help get character in string position

CLEO related
Status
Not open for further replies.

WaTTi

Well-known member
Joined
Jan 4, 2015
Messages
260
Reaction score
8
title..

example

getcharinpos "qwertypro" 3

returned string "e"
 

WaTTi

Well-known member
Joined
Jan 4, 2015
Messages
260
Reaction score
8
Code:
    format 0@ "qewew" 
      
    0@ += 2
    format 1@ "%c" 0@
    
    log "%s" 1@ 

result was "Á" or.. "R" or.. "`", etc.
 

WaTTi

Well-known member
Joined
Jan 4, 2015
Messages
260
Reaction score
8
Code:
// call @GetChar 2 string 0@ pos 1@ to 2@
:GetChar
0C17: 8@ = 0@
if 801D: 1@ > 8@
then 
    9@ = 0
    while 001D: 1@ > 9@
        inc(0@)
        9@+=1
    end 
    0C2D: strrev in 0@ out 0@
    0062: 8@ -= 1@
    9@ = 0
    8@ -= 1
    while 001D: 8@ > 9@
        inc(0@)
        9@+=1
    end
end
ret 1 0@
[font=Monaco, Consolas, Courier, monospace]so.. i did this shit and worked, if some need it.[/font]
 
Joined
Dec 31, 2015
Messages
712
Reaction score
27
Woops.. That was a bad example from me yesterday.. Lol.. However simple sampfunc opcode will solve this problem so you don't have to make 15+ lines snippet..

Code:
alloc 0@ 128
format 0@ "dick"
alloc 1@ 4
//
0@ += 2
0C24: strncpy destination 1@ source 0@ size 1

log "%s | %s" 0@ 1@ 
//log : ck | c
//
free 0@
free 1@
 
Status
Not open for further replies.
Top