Thursday 15 January 2015

Using modulo in Swift strings - how do you capitalise every other letter? -


I'm looking at the swift app to capitalize every other letter in the JavaScript I will use the following: < / P>

  var word = "hello world" word = word. Location (/ [AG] / g, function (c, i) {return i% 2 = == 0? C.toUpperCase (): c;});  

Returns:

  "Hello Woolld"  

How do you implement it in Swift?

A big thanks in advance, I have slipped on the web for an answer and one can not get one, so any help would be greatly appreciated.

If you are searching for a letter change from two to upper case, then do this trick Should: "NewStr + = s.uppercaseString} else {newStr + = s}} println (newStr)

Demo:

However, if you want to search only the replacement range method in case of upper specific category.


No comments:

Post a Comment