From: Orion Hunter Date: 2003-11-27T03:08:17+09:00 Subject: Dumb str.sub question I feel really dumb asking this, but I just can't seem to figure it out. I am trying to parse some text for use in a mysql insert statement. That being the case, I need to escape out quote characters. If str= "isn't stands for is not", what I want is a string with "isn\'t stands for is not" At first I thought, sure, no problem!! But I can't get it. I've tried the following: irb:1> str = "isn't stands for is not" irb:2> str.sub( '\'', '\'' ) --> "isn't stands for is not" (expected) irb:3> str.sub( '\'', '\\'' ) --> unterminated string (expected) irb:4> str.sub( '\'', '\\\' ) --> "isnt stands for is nott stands for is not" (huh? Why this wierd double take?) irb:5> str.sub( '\'' ){ |m| m = "\'" } --> "isn't stands for is not" (expected) irb:6> str.sub( '\'' ){ |m| m = "\\'" } --> "isn\\'t stands for is not" (why did it insert TWO \'s?, and not just one? I would have exected the first one to "escape" the second, thus giving \' as desired) So, my quesitons are: 1) How do I do my escape character substituion 2) Why did #4 and #6 behave as they did? Thanks. _________________________________________________________________ Gift-shop online from the comfort of home at MSN Shopping! No crowds, free parking. http://shopping.msn.com