Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Replacing a word in a range???? CHALLENGE

var peterPiper = "Peter Piper picked a peck of pickled peppers."

// Use the range() method to locate the word "picked"  in peterPiper and assign the 
//range to a variable.

var cheese = peterPiper.range(of: "picked")

for cheese in 1...8 {
          print("\cheese") is the number \(cheese + 1)")
}
//or
//var peterPiper = "Peter Piper picked a peck of pickled peppers."
// let count = peterPiper.count
 //for i in 0..<count {
 //print("Word \(i + 1) is called \(peterPiper[i])")

//how does the above look with the questions asked?
//Replace the word "picked" with "planted."  Expand the view of the result.
//Hint: You can access the upper and the lower bounds of a range with
//.lowerbound   and  .upperbound.....(((((I don't know how to replace  "picked" with "planted"


```swift
let range = peterPiper.range(of: "picked")
range?.lowerbound
range?.upperbound

if let i = peterPiper.index(of: "picked") {
    peterPIper[i] = "Planted"
}
//should look like this
//"Peter Piper picked a peck of pickled peppers."

//End Code.
//Now can anyone see if this works? Please... ?
//string interpolation? ugh

1 Answer

You are amazing, seriously....