Changes

String Functions and Manipulation in VB6

5,158 bytes added, 08:16, 12 February 2008
The following lines were added (+) and removed (-):
== Asc (function) ==== Functions and Description == === Asc (function) ===== Chr (function) ===== Chr (function) ===== InStr (function) ===== InStr (function) ===== InStrRev (function) ===== InStrRev (function) ===== Join (function) ===== Join (function) ===== Mid (function) ===== Mid (function) ===== Replace (function) ===== Replace (function) ===== Reverse (function) ===== Reverse (function) ===== Split (function) ===== Split (function) ===== StrComp (function) ===== StrComp (function) ===== Performance Rating ==table 1{| class="stylish"|+ Relative performance of VB6 string functions|-! Function! Performance! Description|-| Len| class="num" | 1| Len(S) returns the number of ''characters'' in string S.<br />''(Note: works differently with UDTs)''|-| LenB| class="num" | 1| LenB(S) returns the number of ''bytes'' in S.|-| AscW| class="num" | 1| AscW(S) returns the ''Unicode value'' of the first character in S.|-| AscB| class="num" | 1| AscB(S) returns the ''first byte'' in S.|-| Asc| class="num" | 7| Asc(S) returns the ''ANSI value'' of the first character in S.|-| ChrW$| class="num" | 17| ChrW$(U) returns a string containing the ''Unicode character'' U.|-| ChrB$| class="num" | 18| ChrB$(B) returns a ''byte string'' containing the ''character'' B.|-| Chr$| class="num" | 24| Chr$(A) returns a string containing the ''ANSI character'' A.|-| Left$| class="num" | 18| Left$(S,x) returns x characters from the ''start'' of S.|-| Right$| class="num" | 21| Right$(S,x) returns x characters from the ''end'' of S.|-| Mid$| class="num" | 24| Mid$(S,x,y) returns y characters from S, starting at the ''x'th'' character.|-| CStr| class="num" | 36| CStr(x) returns the string representation of x (localized).|-| Str$| class="num" | 111| Str$(x) returns the string representation of x (not localized).|}How to read the table: Calling Len takes 1 unit of time, while Asc takes 7 units. You can call Len 7 times in the same time you call Asc once.table 2<TABLE CLASS="stylish"><CAPTION>Relative performance of VB6 string functions</CAPTION><TR><TH>Function</TH><TH>Performance</TH><TH>Description</TH></TR><TR><TD>LTrim$</TD><TD CLASS="num">20</TD><TD>LTrim$(S) returns a copy of S without <EM>leading</EM> spaces.</TD></TR><TR><TD>RTrim$</TD><TD CLASS="num">21</TD><TD>RTrim$(S) returns a copy of S without <EM>trailing</EM> spaces.</TD></TR><TR><TD>Trim$</TD><TD CLASS="num">29</TD><TD>Trim$(S) returns a copy of S without <EM>leading or trailing</EM> spaces.</TD></TR><TR><TD>Val</TD><TD CLASS="num">89</TD><TD>Val(S) returns the numeric value contained in S (non-localized).</TD></TR><TR><TD>CInt</TD><TD CLASS="num">81</TD><TD>CInt(S) returns the integer value contained in S (localized, rounded).</TD></TR><TR><TD>CDbl</TD><TD CLASS="num">103</TD><TD>CDbl(S) returns the double floating point value contained in S (localized).</TD></TR><TR><TD>LCase$</TD><TD CLASS="num">53</TD><TD>LCase$(S) returns a copy of S with <EM>lower case letters</EM>.</TD></TR><TR><TD>UCase$</TD><TD CLASS="num">53</TD><TD>UCase$(S) returns a copy of S with <EM>upper case letters</EM>.</TD></TR><TR><TD>StrConv(vbLowerCase)</TD><TD CLASS="num">327</TD><TD>StrConv(S,vbLowerCase) returns a copy of S with <EM>lower case letters</EM>.</TD></TR><TR><TD>StrConv(vbUpperCase)</TD><TD CLASS="num">333</TD><TD>StrConv(S,vbUpperCase) returns a copy of S with <EM>upper case letters</EM>.</TD></TR><TR><TD>StrComp(vbBinaryCompare)</TD><TD CLASS="num">47</TD><TD>StrComp(S1,S2,vbBinaryCompare) compares string S1 and S2 based on their <EM>Unicode values</EM>.</TD></TR><TR><TD>StrComp(vbTextCompare)</TD><TD CLASS="num">65</TD><TD>StrComp(S1,S2,vbTextCompare) compares string S1 and S2 in a <EM>locale-dependent, case-insensitive way</EM>.</TD></TR><TR><TD>InStr(vbBinaryCompare)</TD><TD CLASS="num">14</TD><TD>InStr(x,S1,S2,vbBinaryCompare) looks for S2 in S1, starting at position x, in a <EM>locale-independent, case-sensitive way</EM>.</TD></TR><TR><TD>InStr(vbTextCompare)</TD><TD CLASS="num">156</TD><TD>InStr(x,S1,S2,vbTextCompare) looks for S2 in S1, starting at position x, using <A HREF="instr.html#vbtextcompare">text comparison</A>.</TD></TR><TR><TD><b style="color:black;background-color:#a0ffff">InStrRev</b>(vbBinaryCompare)</TD><TD CLASS="num">69</TD><TD><b style="color:black;background-color:#a0ffff">InStrRev</b>(S1,S2,x,vbBinaryCompare) looks for S2 in S1, from position x back to 1, in a <EM>locale-independent, case-sensitive way</EM>.</TD></TR><TR><TD><b style="color:black;background-color:#a0ffff">InStrRev</b>(vbTextCompare)</TD><TD CLASS="num">193</TD><TD><b style="color:black;background-color:#a0ffff">InStrRev</b>(S1,S2,x,vbTextCompare) looks for S2 in S1, from position x back to 1, using <A HREF="instr.html#vbtextcompare">text comparison</A>.</TD></TR><TR><TD><b style="color:black;background-color:#99ff99">Replace</b>(vbBinaryCompare)</TD><TD CLASS="num">375</TD><TD><b style="color:black;background-color:#99ff99">Replace</b>(S1,S2,S3,x,y,vbBinaryCompare) replaces S2 with S3 in S1, starting at position x, max y times, in a <EM>locale-independent, case-sensitive way</EM>.</TD></TR><TR><TD><b style="color:black;background-color:#99ff99">Replace</b>(vbTextCompare)</TD><TD CLASS="num">513</TD><TD><b style="color:black;background-color:#99ff99">Replace</b>(S1,S2,S3,x,y,vbBinaryCompare) replaces S2 with S3 in S1, starting at position x, max y times, using <EM>text comparison</EM>.</TD></TR></TABLE>Reference: http://www.aivosto.com/vbtips/stringopt2.html
Bureaucrat, administrator
16,192
edits