Linked Questions

131 votes
2 answers
93k views

I need to get the last 4 letters of a string. How can I do that? The length of the string varies. Example: var a = "StackOverFlow" var last4 = a.lastFour // That's what I want to do print(...
do it better's user avatar
  • 4,846
-2 votes
1 answer
752 views

If I want to get a value from the NSString "😃hello World😃", what should I use? The return value I want is "hello World". The smileys can be any string. so i need some regexp to this.
Csabi's user avatar
  • 3,093
0 votes
1 answer
200 views

Could someone pls tell me how i get a subString from a String? I tried everything with substring and rangeOfString methods but can't solve it... My text goes like this: var text = "Suuuuper, {1} has ...
S. Birklin's user avatar
  • 1,425
0 votes
1 answer
129 views

How do I substring a string in swift 4. I would like to convert: "Hello, World!" Into: "Hello"
Luke Roberts's user avatar
584 votes
51 answers
329k views

How can I create a UIColor from a hexadecimal string format, such as #00FF00?
Rupesh's user avatar
  • 7,896
436 votes
16 answers
232k views

Does Swift have a trim() method on String? For example: let result = " abc ".trim() // result == "abc"
tounaobun's user avatar
  • 14.9k
222 votes
33 answers
282k views

It's time to admit defeat... In Objective-C, I could use something like: NSString* str = @"abcdefghi"; [str rangeOfString:@"c"].location; // 2 In Swift, I see something similar: var str = "...
Matt Wilding's user avatar
  • 20.2k
121 votes
23 answers
164k views

I want to learn the best/simplest way to turn a string into another string but with only a subset, starting at the beginning and going to the last index of a character. For example, convert "www....
Jason Hocker's user avatar
  • 7,077
117 votes
2 answers
82k views

I'm trying to test if a Swift string starts or ends with a certain value. These methods do not exist: var str = "Hello, playground" str.startsWith("Hello") // error str.endsWith("ground") // error I ...
Suragch's user avatar
  • 516k
67 votes
1 answer
60k views

I get compiler error at this line: UIDevice.currentDevice().identifierForVendor.UUIDString.substringToIndex(8) Type 'String.Index' does not conform to protocol 'IntegerLiteralConvertible' My ...
János's user avatar
  • 35.5k
36 votes
13 answers
23k views

So split("There are fourty-eight characters in this string", 20) should return ["There are fourty-eig", "ht characters in thi","s string"] If I make currentIndex = string.startIndex and then try to ...
yshilov's user avatar
  • 804
24 votes
13 answers
33k views

I'm trying to use UITextFieldDelegate in Swift/Xcode6 and I'm struggling with the way I'm supposed to use stringByReplacingCharactersInRange. The compiler error is 'Cannot convert the expression's ...
Seppo's user avatar
  • 585
26 votes
3 answers
12k views

With Beta 3 all worked fine, now I get a strange error, and I have no clue how to fix it. Tried all the solutions for similiar problems. Here is my code: if !name.isEmpty { var splitted: [...
mort3m's user avatar
  • 481
15 votes
1 answer
16k views

To remove a substring at a specified range, use the removeRange(_:) method: 1 let range = advance(welcome.endIndex, -6)..<welcome.endIndex 2 welcome.removeRange(range) 3 println(welcome) 4 // ...
user avatar
10 votes
2 answers
5k views

My goal is to mark all visible misspelled words in an UITextView. The inefficient algorithm is to use the spell checker to find all ranges of misspelled words in the text, convert them to ...
Anders Sewerin Johansen's user avatar

15 30 50 per page