Gort Posted October 17, 2007 Share Posted October 17, 2007 I need to catch empty string. (~%string%~ STRING_COMPARE_CASE ~~ = 0) and (~%string%~ STRING_MATCHES_REGEXP ~^$~ = 0) does not work. How is it possible? Link to comment
CamDawg Posted October 17, 2007 Share Posted October 17, 2007 (~%string%~ STRING_COMPARE_CASE ~~ = 0) This is what I use. I think you may need "%string%" instead of ~%string%~. Link to comment
devSin Posted October 17, 2007 Share Posted October 17, 2007 No, it absolutely should work the same with tildes, quotes, percents, or anything else. I'd check to make sure that the string is actually empty and not a space (0x20) or other non-printable character hiding in the bushes. Link to comment
Gort Posted October 18, 2007 Author Share Posted October 18, 2007 The string is not a space, this I know. But how I'd check if there're some non-printable characters? Link to comment
devSin Posted October 18, 2007 Share Posted October 18, 2007 Try COPY_EXISTING SW1H01.ITM OVERRIDE READ_ASCII 0x0 nil (0) PATCH_IF !("%nil%" STRING_COMPARE_CASE "") BEGIN PATCH_PRINT "Empty string HUZZAH!!!" END BUT_ONLY_IF_IT_CHANGES If that works, your "%string%" must not be a true zero-length string. If it doesn't work, shout at the_bigg on the WeiDU forums at PPG. Link to comment
Gort Posted October 18, 2007 Author Share Posted October 18, 2007 I'll try, but anyway, I need to detect my string, even if it's not really empty and consists of only non-printable characters. Can this be done? Link to comment
Nythrun Posted October 18, 2007 Share Posted October 18, 2007 I generally use this to set up an array of all the ascii characters: OUTER_PATCH ~this_is_not_a_variable~ BEGIN FOR ("i1" = 0x0; "i1" < 0x100; "i1" += 0x1) BEGIN WRITE_BYTE 0x0 "i1" READ_ASCII 0x0 ~c~ (0x1) SPRINT EVALUATE_BUFFER ~0t%i1%~ ~%c%~ END END Which will allow detecting of any whitespace characters, or nothing, with: PATCH_IF !(~%string%~ STRING_MATCHES_REGEXP ~\(%0t0%\|%0t9%\|%0t10%\|%0t13%\|%0t32%\)*~) THEN BEGIN You could also rob Cam's EXTRA_REGEXP_VARS lib for some of these. Link to comment
Gort Posted October 19, 2007 Author Share Posted October 19, 2007 TryCOPY_EXISTING SW1H01.ITM OVERRIDE READ_ASCII 0x0 nil (0) PATCH_IF !("%nil%" STRING_COMPARE_CASE "") BEGIN PATCH_PRINT "Empty string HUZZAH!!!" END BUT_ONLY_IF_IT_CHANGES If that works, your "%string%" must not be a true zero-length string. If it doesn't work, shout at the_bigg on the WeiDU forums at PPG. this works, therefore my string is not empty I generally use this to set up an array of all the ascii characters:OUTER_PATCH ~this_is_not_a_variable~ BEGIN FOR ("i1" = 0x0; "i1" < 0x100; "i1" += 0x1) BEGIN WRITE_BYTE 0x0 "i1" READ_ASCII 0x0 ~c~ (0x1) SPRINT EVALUATE_BUFFER ~0t%i1%~ ~%c%~ END END Which will allow detecting of any whitespace characters, or nothing, with: PATCH_IF !(~%string%~ STRING_MATCHES_REGEXP ~\(%0t0%\|%0t9%\|%0t10%\|%0t13%\|%0t32%\)*~) THEN BEGIN You could also rob Cam's EXTRA_REGEXP_VARS lib for some of these. thanks, I'll try this Link to comment
Recommended Posts
Archived
This topic is now archived and is closed to further replies.