diff options
| author | ruki <waruqi@gmail.com> | 2019-06-05 22:33:50 +0800 |
|---|---|---|
| committer | ruki <waruqi@gmail.com> | 2019-06-05 09:23:20 +0800 |
| commit | 894bc38bd69e997095b5b899787a74a48229d172 (patch) | |
| tree | 78e044cc7a018ec09094045103648db52b96a940 /manual.md | |
| parent | cb83cf953c9b6d3a734a9e4aca1cc22c78966c29 (diff) | |
| download | xmake-docs-894bc38bd69e997095b5b899787a74a48229d172.tar.gz xmake-docs-894bc38bd69e997095b5b899787a74a48229d172.zip | |
update string.split
Diffstat (limited to 'manual.md')
| -rw-r--r-- | manual.md | 35 |
1 files changed, 27 insertions, 8 deletions
@@ -6461,23 +6461,42 @@ end ###### string.split -- Split string +pattern match and ignore empty string -The string is separated by the specified separator. The separator can be: character, string, pattern matching string, for example: +```lua +("1\n\n2\n3"):split('\n') => 1, 2, 3 +("abc123123xyz123abc"):split('123') => abc, xyz, abc +("abc123123xyz123abc"):split('[123]+') => abc, xyz, abc +``` + +plain match and ignore empty string + +```lua +("1\n\n2\n3"):split('\n', {plain = true}) => 1, 2, 3 +("abc123123xyz123abc"):split('123', {plain = true}) => abc, xyz, abc +``` + +pattern match and contains empty string ```lua -local s = "hello xmake!" -s:split("%s+") +("1\n\n2\n3"):split('\n', {strict = true}) => 1, , 2, 3 +("abc123123xyz123abc"):split('123', {strict = true}) => abc, , xyz, abc +("abc123123xyz123abc"):split('[123]+', {strict = true}) => abc, xyz, abc ``` -Split according to consecutive whitespace characters, the result is: `hello`, `xmake!` +plain match and contains empty string ```lua -local s = "hello,xmake:123" -s:split("[,:]") +("1\n\n2\n3"):split('\n', {plain = true, strict = true}) => 1, , 2, 3 +("abc123123xyz123abc"):split('123', {plain = true, strict = true}) => abc, , xyz, abc ``` -The above code is split according to the `, ` or `:` characters. The result is: `hello`, `xmake`, `123` +limit split count + +```lua +("1\n\n2\n3"):split('\n', {limit = 2}) => 1, 2\n3 +("1.2.3.4.5"):split('%.', {limit = 3}) => 1, 2, 3.4.5 +``` ###### string.trim |
