sktan7 12 Posted September 24, 2012 Report Share Posted September 24, 2012 Hi,Not sure if anyone came across substring out of range problem.There is a bug in ubot that does not check for out of range.Therefore I created my substring2. =========================== start here ============================define $substring2(#substring2_text, #substring2_starting, #substring2_number_of_character) { set(#substring2_length, $text length(#substring2_text), "Local") comment("There are 3 bugs with substring function The 1st bug: the 3rd parameter, if exceed the string position, the substring function will generate an error The 2nd bug: The substring does not check if the starting position is valid, if the starting position is beyond the maximum string length, the substring function will generate an error The 3rd bug: the substring generate an error if the last paramater is a space Enhancement 1 1st bug: default the maximum number of character, 3rd substring parameter to the max number of character before the end of string for example: if the string is 'abc1234', starting position is 3, number of character is 10 The substring2 function will change the 3rd substring parameter to 4 Enhancement 2 2nd bug: if the starting position is not valid, change it to the last character position, at the same time, the maximum number of character will become zero example: string is 'abc1234', the string length is 7 parameter 1: 8, parameter 2 substring2 will change the parameter 1 to '7' and parameter to '0' Enhancement 3 - unfornately, this cannot be solved as ubot will generate an error when substring2 is called. The 3rd enhancement does not work. if the last parameter for substring is a space, default to maximum allow character, based on the starting position example string 'abc1234', starting position is 0, number of character is blank substring2 will change the 3rd parameter to 7") if(#substring2_length < #substring2_starting) { then { set(#substring2_starting, #substring2_length, "local") set(#substring2_number_of_character, 0, "local") } } if(#substring2_number_of_character = "") { then { set(#substring2_max_character, $subtract(#substring2_length, #substring2_starting), "local") } } if(#substring2_length < $add(#substring2_starting, #substring2_number_of_character)) { then { set(#substring2_max_character, $subtract(#substring2_length, #substring2_starting), "local") return($substring(#substring2_text, #substring2_starting, #substring2_max_character)) } else { return($substring(#substring2_text, #substring2_starting, #substring2_number_of_character)) } }}============================== end here =========================== Quote Link to post Share on other sites
k1lv9h 76 Posted September 24, 2012 Report Share Posted September 24, 2012 Hi, Sample code:ui text box("start pos", #sp1startpos) if($comparison(#sp1startpos, "=", $nothing)) { then { set(#sp1startpos, 3, "Global") } else { } } ui stat monitor("texts value:", "==>{#texts}<==") ui stat monitor("texts length", $text length(#texts)) ui stat monitor("sub start", #sp1startpos) set(#numofchar, $subtract($text length(#texts), #sp1startpos), "Global") ui stat monitor("num of chars", #numofchar) ui stat monitor("substr value", "==>{#substrtextsvalue1}<==") set(#texts, "abc1234 ", "Global") if($comparison(#sp1startpos, ">", $text length(#texts))) { then { set(#substrtextsvalue1, "Start position not below texts length", "Global") } else { set(#substrtextsvalue1, $substring(#texts, #sp1startpos, $subtract($text length(#texts), #sp1startpos)), "Global") } } sample-substring-test-001.ubot Kevin Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.