Skip to content
Advertisement

Adding string to a string before some certain characters?

myString = '(247, 246, 244), (13, 23, 24), (85, 101, 100)'

substring = 'rgb'
  • I want to add this string the substring above, before every ‘(‘ character. So that it would be look like this below.

    myString = ‘rgb(247, 246, 244), rgb(13, 23, 24), rgb(85, 101, 100)’

Advertisement

Answer

Try using the .replace() method, ie myString.replace("(", "rgb(") this will just go through the string and replace every "(" with "rgb(".

Advertisement