Skip to content

Commit 2a46518

Browse files
authored
Update 769-string-split.markdown
1 parent 68ddf11 commit 2a46518

File tree

1 file changed

+37
-7
lines changed

1 file changed

+37
-7
lines changed

_build/reference/769-string-split.markdown

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,53 @@
22

33
> SPLIT string, delimiters, words() [, pairs] [USE expr]
44
5-
Returns the words of the specified string into array 'words'.
5+
Splits "string" at the position of the given delimiters and returns the words of the specified string into array 'words'. "pairs" can be used to group words. "Use expr" is applied to every splitted word.
66

77
```
88
s="/etc/temp/filename.ext"
9-
SPLIT s, "/.", v()
9+
SPLIT s, "/.", v() ' Splits the string using the delimiters "/" and "."
1010
FOR i=0 TO UBOUND(v)
1111
PRINT i;" [";v(i);"]"
1212
NEXT
13+
14+
' displays:
15+
' 0 []
16+
' 1 [etc]
17+
' 2 [temp]
18+
' 3 [filename]
19+
' 4 [ext]
1320
```
1421

15-
displays:
22+
Example for using the argument "pairs"
1623

1724
```
25+
s = "/etc/temp/filename.ext"
26+
SPLIT s, "/", v(), "temp"
27+
FOR i = 0 TO UBOUND(v)
28+
PRINT i;" [";v(i);"]"
29+
NEXT
30+
31+
' Display
1832
0 []
19-
1 [etc]
20-
2 [temp]
21-
3 [filename]
22-
4 [ext]
33+
1 [etc/temp]
34+
2 [filename.ext]
35+
```
36+
37+
Example for using "USE expr"
38+
39+
```
40+
s = "/etc/temp/filename1.ext " ' additional spaces at the end of the string
41+
SPLIT s, "/", v(), "temp" USE TRIM(x) ' trim(x) will remove spaces at the beginning
42+
' and the end of the splitted strings;
43+
' try the example without "USE TRIM(x)"
44+
FOR i = 0 TO UBOUND(v)
45+
PRINT i;" [";v(i);"]"
46+
NEXT
47+
48+
' displays
49+
' 0 []
50+
' 1 [etc/temp]
51+
' 2 [filename1.ext]
2352
```
2453

54+

0 commit comments

Comments
 (0)