Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Character-to-byte unicode strings index conversion
#1
I have written this short macro to convert a character index (i0) in a unicode string (s) to its equivalent byte index (j), for search purposes, as for example in the case of "from" the zero-based character index, from which to start search. I would appreciate any comments, indeed in the case there exists a smart way to do this conversion.

Function iniuni
Code:
Copy      Help
;str s ;; unicode string to be searched
;int i0 ;; character index

int j
if i0 > 0
,j=2*i0
,str s3 s4 s5
,s3.unicode(s)
,s4.get(s3 0 j)
,s5.ansi(s4 -1)
,j=s5.len - 1
,out "%s %i" si j

ret j


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)