mardi 7 avril 2020

Looping through array targeting upcase letters only

Am trying to loop through a string which i have converted to an array and target only the upcase letters which i will then insert an empty space before the capitalized letter. My code checks for the first cap letter and adds the space but am struggling to do it for the next cap letter which in this case is "T". Any advise would be appreciated. Thanks

  def break_camel(str)
  # ([A-Z])/.match(str)
  saved_string = str.freeze
  cap_index =str.index(/[A-Z]/)
  puts(cap_index)

   x =str.split('').insert(cap_index, " ")
  x.join

end
break_camel("camelCasingTest")

Aucun commentaire:

Enregistrer un commentaire