Swift : substringWithRange() function example
A quick tutorial as add on from previous tutorial on how to get sub-string with rangeOfString() function. Another way to get sub string in Swift is to use the substringWithRange()
function.
For example :
var str = "Hello World!"
str.substringWithRange(Range<String.Index>(start: str.startIndex, end: str.endIndex))
Output :
"Hello World!"
and if you want to start from position 3 and position -1 from end. Change the start
and end
position with advance()
function.
var str = "Hello World!"
str.substringWithRange(Range<String.Index>(start: advance(str.startIndex, 3), end: advance(str.endIndex, -1)))
Output :
"lo World"
See also : Swift : Get substring with rangeOfString() function example
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+14.5k Golang : Rename directory
+5.1k Golang : Display packages names during compilation
+9.8k Golang : Qt get screen resolution and display on center example
+12.4k Golang : Encrypt and decrypt data with x509 crypto
+4.4k Golang : Valued expressions and functions example
+12.4k Golang : Validate email address
+16.5k Golang : How to implement two-factor authentication?
+26.7k Golang : How to check if a connection to database is still alive ?
+8.3k Golang : Configure Apache and NGINX to access your Go service example
+14.4k Golang : On enumeration
+10.6k Golang : How to delete element(data) from map ?
+21.8k Golang : Setting up/configure AWS credentials with official aws-sdk-go