Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

String-Split Function parameter "compare"

  Asked By: Daisy    Date: Feb 17    Category: MS Office    Views: 1363
  

This function splits a string variable into array elements based
seperated by a delimiter 'character'. Nice for parsing strings with
variable length , delimited sections.

Any one KNOW what the last parameter "comparison type" is? Compare what?

The best I can figure is that it refers to figuring out what is the
delimiting byte/character/element in the string. Perhaps it allows
either using a printable ASCII character as a delimiter (use textual
compare). This is when the string contains simple ASCII text.
Since you can also stuff simple binary values into a string (if you
print the string you see garbage since it isn't meaningful printable
ASCII), you may want some arbitrary value to delimit on (like, say
zero, or 127/7F) FOr this. perhaps you use the binary compare. Then
you can delimit on any value, not just printable text.

MSDN and Excel macro help are un-enlightening as usual. I could spend
manu hours experimenting to breach the chasim...

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Kiet Jainukul     Answered On: Feb 17

The delimiter character(s) with the characters in the string  being
split.

I found this under "Option Compare Statement" in the help  file:

Option Compare binary  results in string comparisons based on a sort
order derived from the internal binary representations of the
characters. In Microsoft Windows, sort order is determined by the code
page. A typical binary sort order is shown in the following example:

A < B < E < Z < a < b < e < z < À < Ê < Ø < à < ê <
ø

Option Compare text  results in string comparisons based on a
case-insensitive text sort order determined by your system's locale.
When the same characters are sorted using Option Compare Text, the
following text sort order is produced:

(A=a) < ( À=à) < (B=b) < (E=e) < (Ê=ê) < (Z=z) <
(Ø=ø)

Translated it seems to mean approximately:
Case sensitive.. or not.

Eg.
Firstly with a textual comparison  (comparison type  = 1):
x = Split("abtcdeTfgthi", "T", -1, 1)
leaves x as a Variant/String(0 to 3) containing the following
elements:
x(0) : "ab"
x(1) : "cde"
x(2) : "fg"
x(3) : "hi"
Note that both "t" and "T" act as delimiters.

Changing only the comparison type to 0 (that's a binary comparison):
x = Split("abtcdeTfgthi", "T", -1, 0)
leaves x as a Variant/String(0 to 1):
x(0) : "abtcde"
x(1) : "fgthi"
Here only "T" acts as a delimiter.

 
Didn't find what you were looking for? Find more on String-Split Function parameter "compare" Or get search suggestion and latest updates.




Tagged: