1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
<?xml version="1.0" encoding="UTF-8"?>
<helpdocument version="1.0">
<!--
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
-->
<meta>
<topic id="textsbasicshared03120314xml" indexer="include" status="PUBLISH">
<title id="tit" xml-lang="en-US">Split Function</title>
<filename>/text/sbasic/shared/03120314.xhp</filename>
</topic>
</meta>
<body>
<section id="split">
<bookmark xml-lang="en-US" branch="index" id="bm_id3156027">
<bookmark_value>Split function</bookmark_value>
</bookmark>
<h1 id="hd_id3156027"><link href="text/sbasic/shared/03120314.xhp">Split Function</link></h1>
<paragraph id="par_id3155805" role="paragraph" xml-lang="en-US">Returns an array of substrings from a string expression.</paragraph>
</section>
<embed href="text/sbasic/shared/00000003.xhp#functsyntax"/>
<bascode>
<paragraph id="par_id3153824" role="bascode" xml-lang="en-US">Split (expression As String, delimiter, limit)</paragraph>
</bascode>
<embed href="text/sbasic/shared/00000003.xhp#functvalue"/>
<paragraph id="par_id3154285" role="paragraph" xml-lang="en-US">With Option VBASupport 1: String, with Option VBASupport 0: Variant/String</paragraph>
<embed href="text/sbasic/shared/00000003.xhp#functparameters"/>
<paragraph id="par_id3156023" role="paragraph" xml-lang="en-US"> <emph>expression</emph>: Any string expression.</paragraph>
<paragraph id="par_id3147560" role="paragraph" xml-lang="en-US"> <emph>delimiter</emph>: An optional string of one or more characters length that is used to delimit <literal>String</literal>. The default is the space character.</paragraph>
<paragraph id="par_id3145069" role="paragraph" xml-lang="en-US"> <emph>limit</emph>: An optional number of substrings that you want to return.</paragraph>
<embed href="text/sbasic/shared/00000003.xhp#functexample"/>
<section id="splitjoinex">
<bascode>
<paragraph id="par_idm1341285008" role="bascode" localize="false">Dim a(3)</paragraph>
<paragraph id="par_idm1341283776" role="bascode" localize="false">Sub main()</paragraph>
<paragraph id="par_idm1341282544" role="bascode" localize="false"> a(0) = "ABCDE"</paragraph>
<paragraph id="par_idm1341281312" role="bascode" localize="false"> a(1) = 42</paragraph>
<paragraph id="par_idm1341280080" role="bascode" localize="false"> a(2) = "MN"</paragraph>
<paragraph id="par_idm1341278848" role="bascode" localize="false"> a(3) = "X Y Z"</paragraph>
<paragraph id="par_idm1341277616" role="bascode" localize="false"> JStr = Join1()</paragraph>
<paragraph id="par_idm1341276384" role="bascode" localize="false"> Call Show(JStr, Split1(JStr))</paragraph>
<paragraph id="par_idm1341275136" role="bascode" localize="false"> JStr = Join2()</paragraph>
<paragraph id="par_idm1341273904" role="bascode" localize="false"> Call Show(JStr, Split1(JStr))</paragraph>
<paragraph id="par_idm1341272656" role="bascode" localize="false"> JStr = Join3()</paragraph>
<paragraph id="par_idm1341271424" role="bascode" localize="false"> Call Show(JStr, Split1(JStr))</paragraph>
<paragraph id="par_idm1341270176" role="bascode" localize="false">End Sub</paragraph>
<paragraph id="par_idm1341268944" role="bascode" localize="false"> </paragraph>
<paragraph id="par_idm1341267696" role="bascode" localize="false">Function Join1()</paragraph>
<paragraph id="par_idm1341266464" role="bascode" localize="false"> Join1 = Join(a(), "abc")</paragraph>
<paragraph id="par_idm1341265216" role="bascode" localize="false">End Function</paragraph>
<paragraph id="par_idm1341263984" role="bascode" localize="false"> </paragraph>
<paragraph id="par_idm1341262784" role="bascode" localize="false">Function Join2()</paragraph>
<paragraph id="par_idm1341261552" role="bascode" localize="false"> Join2 = Join(a(), ",")</paragraph>
<paragraph id="par_idm1341260304" role="bascode" localize="false">End Function</paragraph>
<paragraph id="par_idm1341259072" role="bascode" localize="false"> </paragraph>
<paragraph id="par_idm1341257872" role="bascode" localize="false">Function Join3()</paragraph>
<paragraph id="par_idm1341256640" role="bascode" localize="false"> Join3 = Join(a())</paragraph>
<paragraph id="par_idm1341255408" role="bascode" localize="false">End Function</paragraph>
<paragraph id="par_idm1341254176" role="bascode" localize="false"> </paragraph>
<paragraph id="par_idm1341252976" role="bascode" localize="false">Function Split1(aStr)</paragraph>
<paragraph id="par_idm1341251744" role="bascode" localize="false"> Split1 = Split(aStr, "D")</paragraph>
<paragraph id="par_idm1341250496" role="bascode" localize="false">End Function</paragraph>
<paragraph id="par_idm1341249264" role="bascode" localize="false"> </paragraph>
<paragraph id="par_idm1341248064" role="bascode" localize="false">Sub Show(JoinStr, TheArray)</paragraph>
<paragraph id="par_idm1341246816" role="bascode" localize="false"> l = LBound(TheArray)</paragraph>
<paragraph id="par_idm1341245568" role="bascode" localize="false"> u = UBound(TheArray)</paragraph>
<paragraph id="par_idm1341244320" role="bascode" localize="false"> total$ = "=============================" + Chr$(13) + JoinStr + Chr$(13) + Chr$(13)</paragraph>
<paragraph id="par_idm1341243024" role="bascode" localize="false"> For i = l To u</paragraph>
<paragraph id="par_idm1341241792" role="bascode" localize="false"> total$ = total$ + TheArray(i) + Str(Len(TheArray(i))) + Chr$(13)</paragraph>
<paragraph id="par_idm1341240496" role="bascode" localize="false"> Next i</paragraph>
<paragraph id="par_idm1341239264" role="bascode" localize="false"> MsgBox total$</paragraph>
<paragraph id="par_idm1341238032" role="bascode" localize="false">End Sub</paragraph>
</bascode>
</section>
<section id="relatedtopics">
<paragraph role="paragraph" id="par_id161599082457466" localize="false"><embedvar href="text/sbasic/shared/00000003.xhp#stringfunctions"/></paragraph>
</section>
</body>
</helpdocument>
|