Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

index string swift

let string = "Hello, World!"
let index = string.index(string.startIndex, offsetBy: 3)

print(string[index]) // Prints "l"

// This can be done in one line too:
print(string[string.index(string.startIndex, offsetBy: 3)])
Comment

string index in swift

extension String {
    subscript(_ n: Int) -> Character {
        return self[self.index(self.startIndex, offsetBy: n)]
    }
}

let str = "Hello World"

print(str[0]) // H
print(str[4]) // o
print(str[6]) // w
Comment

PREVIOUS NEXT
Code Example
Swift :: swift reload tableview 
Swift :: swift round double to 2 decimal places 
Swift :: unit testing swift ui 
Swift :: swift scroll to tableviewcell 
Swift :: swift ui enum 
Swift :: navigation title bar color swftui 
Swift :: string.format swift 
Swift :: swift 5 get current date date 
Swift :: change font of substring swift 
Swift :: swift hello world 
Swift :: swift get "system" asset image 
Swift :: uibutton swift set title color 
Swift :: uiview set inside padding 
Swift :: swiftui textfield editable false 
Swift :: sf symbols 
Swift :: hello world in swift 
Swift :: UIFont.init bold 
Swift :: How to convert String into Array of character 
Swift :: Swift if..else if 
Swift :: swift get keys from dictionary 
Swift :: share local storage wkwebview swift 
Swift :: table view content size not return correctly 
Swift :: Swift Change Value of Dictionary 
Swift :: var i = 2 repeat { i *= i * 2 } while i < 100 print(i) 
Swift :: implement swift protocol in kotlin 
Swift :: swift check if class is of type 
Swift :: uilabel without constraint 
Swift :: how request prefix of string in swift 
Swift :: swift float 
Swift :: swift convert frame to another view 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =