Linked Questions
35 questions linked to/from How does String substring work in Swift
-3
votes
2
answers
3k
views
Swift - sum range.location and range.length [duplicate]
I have following Obj-c statement:
string = [string substringFromIndex:(range.location + range.length)];
What it's Swift equivalent?
0
votes
1
answer
639
views
Swift 4: return Substring index from a String [duplicate]
I checked lots of similar questions here, the answers to which do not seem to be a working solution for me. I am reading a formatted File into a string "Substring #1: Hello World!; Substring #2: My ...
0
votes
1
answer
135
views
Creating A Substring | Swift 4 [duplicate]
How do I substring a string in swift 4.
I would like to convert:
"Hello, World!"
Into:
"Hello"
1
vote
1
answer
47
views
Simple function resulting in Type of expression is ambiguous without more context - SwiftUI [duplicate]
this function is supposed to just get a substring but I can't seem to quite get it.
I've tried pretty much all combinations of types but nothing seems to work
Code Causing the error:
let final = temp....
517
votes
48
answers
458k
views
Get nth character of a string in Swift
How can I get the nth character of a string? I tried bracket([]) accessor with no luck.
var string = "Hello, world!"
var firstChar = string[0] // Throws error
ERROR: 'subscript' is unavailable: ...
129
votes
10
answers
163k
views
How to create range in Swift?
In Objective-c we create range by using NSRange
NSRange range;
So how to create range in Swift?
114
votes
11
answers
151k
views
Index of a substring in a string with Swift
I'm used to do this in JavaScript:
var domains = "abcde".substring(0, "abcde".indexOf("cd")) // Returns "ab"
Swift doesn't have this function, how to do something similar?
156
votes
5
answers
171k
views
How does String.Index work in Swift
I've been updating some of my old code and answers with Swift 3 but when I got to Swift Strings and Indexing it has been a pain to understand things.
Specifically I was trying the following:
let ...
85
votes
9
answers
64k
views
'subscript' is unavailable: cannot subscript String with a CountableClosedRange<Int>, see the documentation comment for discussion
In Swift 4, I'm getting this error when I try to take a Substring of a String using subscript syntax.
'subscript' is unavailable: cannot subscript String with a CountableClosedRange, see the ...
7
votes
4
answers
17k
views
How do you limit UILabel characters in swift?
I'm trying to set a limit in my label to 10 characters, I'm a complete newbie to programming in general so its my 3rd month so far... anyway thanks in advance :-)
4
votes
3
answers
13k
views
How to get a substring in swift 4?
I know we can use subscript to cut a part of the string in Swift 4, .
let s = "aString"
let subS = s[..<s.endIndex]
But the problem is, how to cut the s to a subString like aStr.
I mean, What I ...
JsW's user avatar
- 1,766
4
votes
6
answers
14k
views
Finding new line character in a String in "Swift 3"
In my app I am receiving some incoming data from a web service. In that data some wrong values can also be received like new line characters. I want to find in response string that if it contains a ...
7
votes
4
answers
3k
views
String may not be indexed with int
I get error in the last line when I try to set label1 to the first letter of string, using latest version of Swift. How to solve this issue?
let preferences = UserDefaults.standard
let name1 = "" + ...
0
votes
3
answers
6k
views
Swift string after specific index [duplicate]
I want to know how to get rest of string after specific character.
I have checked link
but have not found answer.
Consider following code:
let fullString = "Blue Sky"
let spaceIndex = fullName....
5
votes
1
answer
5k
views
How do you split a string at every n-th character in Swift? [duplicate]
Like the question says, if I have:
XQQ230IJFEKJLDSAIOUOIDSAUIFOPDSFE28
How can I split this string at every 8th character to get:
XQQ230IJ FEKJLDSA IOUOIDSA UIFOPDSA