-2
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)'

petezurich
  • 9,280
  • 9
  • 43
  • 57

2 Answers2

0

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

petezurich
  • 9,280
  • 9
  • 43
  • 57
Jerry Spice
  • 63
  • 1
  • 8
0

Just showing full implementation of Jasonharper's, where you change how you define your sub-string and replace the opening parenthesis:

myString = '(247, 246, 244), (13, 23, 24), (85, 101, 100)'
substring = 'rgb('
myString.replace("(", substring)
Siesmic_
  • 71
  • 1
  • 5