I am trying to globally replace characters in a string by "chaining" the
String#gsub method like so:
str = "count=(a+b); if(a<=b) d[i]=10;f(a,b)"
puts str.gsub(/,/,' , ').gsub(/\(/,' ( ').gsub(/\)/,' )
').gsub(/([^<>])=/,'\1 = ').gsub(/;/,";\n")
Is there a better (faster) way to do this ?
Here is how I want the replacement to work:
';' --- to be replaced by --> ';\n' new line after
',' ------------------------> ' , ' single space on either side
'(' ------------------------> ' ( ' single space on either side
')' ------------------------> ' ) ' single space on either side
'=' ------------------------> ' = ' single space on either side except when
preceded by < or >
I am using ruby 1.7.3 (2002-11-17) [i386-mswin32]
TIA,
-shanko