NthField
From REALbasicWiki
| Overall article skill | ✭ |
NthField splits the passed string aString into fields as defined by the value of the separator parameter, then returns the field at position index. The index parameter is 1-based. Splitting into fields respects encodings. For splitting that ignores encodings, use NthFieldB. if the index is less than 1 or greater than the value returned by CountFields), NthField returns ""; it does not raise an OutOfBoundsException.
Contents |
[edit] Prototype
Function NthField(aString as String, separator as String, index as Integer) as String
[edit] Discussion
NthField starts anew each time it is called. Thus, using it in a loop to extract fields can be quite slow. Instead you should use Split, which returns all fields in an array.
[edit] Sample Code
In this bit of sample code, NthField returns the value "Cupertino".
return NthField("1 Infinite Loop,Cupertino, CA, 95014", ",", 2)
[edit] See also
- CountFields method
- Split method
