I am using the NLTokenizer to display the list of tokens in swift playground.
How can i display the index numbers before the tokens ?
Like:
1.Introduction
2.to
3.Natural
4.Language
5.Processing
I am using the NLTokenizer to display the list of tokens in swift playground.
How can i display the index numbers before the tokens ?
Like:
1.Introduction
2.to
3.Natural
4.Language
5.Processing
You can use a variable for this.(Here you can start index with 1)
var index = 0
tokenizer.enumerateTokens(in: str.startIndex..<str.endIndex) { (range, token) -> Bool in
print("Index: \(index).\(str[range])")
index += 1
return true
}
Output
Index: 0. Introduction
Index: 1. to
Index: 2. Natural
Index: 3. Language
Index: 4. Processing
You can try the snippet below.