This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Split a string into many string!
#1
Heart 
Please help me, if anybody can do!
 I have a any string "abcd12345678901234567". Now I want to split the strings into two strings:
- The first string from the first letter to the 14th character. "abcd1234567890"
- The last string is from the 15th character to the end of the string. "1234567".
- Count the number of characters in the string "abcd12345678901234567". Because this string is always changing. so I need the last string to get the correct value ending.
Who can help me? thank you very much.
Reply
#2
Code:
str = 'abcd12345678901234567'
-- get length of a string
len = #str
-- get first 14 characters
a = string.sub(str, 1, 14)
-- get remaining characters
b = string.sub(str, 15)
Reply
#3
Thank you very much admin!
I have a little question! please help me!
I have a string "Hold me tight or don't", but when displayed on the screen KNX it appears "Hold me tight or don't". Does KNX have no unicode code? and it transforms code(') into (' )
To be correct, please help me write a script:
-Search strings (' ) in string "Hold me tight or don't" and then change to (').
Thank so much!
Reply
#4
Hi,

Use this:
Code:
str = 'Hold me tight or don't'
str = string.gsub(str, ''', "'")
log(str) -- Hold me tight or don't

Other metadata options are in this function:

Code:
function unescapemetadata(str)
    str = string.gsub( str, '%%3a', ':' )
    str = string.gsub( str, '%%2f', '/' )
    str = string.gsub( str, '&lt;', '<' )
    str = string.gsub( str, '&gt;', '>' )
    str = string.gsub( str, '&quot;', '"' )
    str = string.gsub( str, '&apos;', "'" )
    str = string.gsub( str, '&#(%d+);', function(n) return string.char(n) end )
    str = string.gsub( str, '&amp;', '&' ) -- Be sure to do this after all others
    return str
end

BR,

Erwin
Reply
#5
very good! I very thank friend! Smile
Reply


Forum Jump: