Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Subfield with consecutive delimiters - a bug?

If I have a string with the occasional multiple delimiters between data, Subfield extracts the delimiter and not the expected data.

Example:

=subfield('abcdef    MyData zzzz', ' ' , 2)

I expect the above to return 'MyData', but it returns ' ' (a space)

I could use the following very ugly statement, but I'm not thrilled about doing so, especially since this needs to be done during a load.

=Subfield(TRIM( MID('abcdef    MyData zzzz',INDEX('abcdef    MyData zzzz',' ',1)) ),' ',1)

Based on my experience with many other languages, I expected the subfield to eat the extra consecutive  delimiters, but that is not happening.

Q1) is this the expected Subfield behavior or a bug?

Q2) Does anyone have a better method than my above expression?

TIA,

John

QV 11.20, SR4

21 Replies
engishfaque
Specialist III
Specialist III

Dear John,

Neither it's bug nor it's expression issue.

It's actually happening due to, you are using double space in expression.

Correct:

=subfield('abcdef MyData zzzz', ' ' , 2)

Your script with spaces:

=subfield('abcdef    MyData zzzz', ' ' , 2)


Kind regards,

Ishfaque Ahmed

robert_mika
Master III
Master III

You are right Colin.

Thanks for the explanation

MarcoWedel

Hi,

as John stated it's human entered data, I tried to extend your solution to work with any number of spaces (for John's users with itchy fingers 😉

QlikCommunity_Thread_149791_Pic1.JPG

tabStrings:

LOAD *,

    RecNo() as ID

Inline [

string

abcdef                                                    MyData          zzzz

abcdef    MyData zzzz

abcdef    MyData zzzz

abcdef  MyData zzzz

abcdef  MyData zzzz

abcdef MyData zzzz

abcdef    MyData  zzzz

abcdef    MyData  zzzz

abcdef  MyData  zzzz

abcdef  MyData  zzzz

abcdef MyData  zzzz

abcdef    MyData  zzzz

abcdef    MyData  zzzz

abcdef  MyData  zzzz

abcdef  MyData  zzzz

abcdef MyData  zzzz

abcdef    MyData    zzzz

abcdef    MyData    zzzz

abcdef  MyData    zzzz

abcdef  MyData    zzzz

abcdef MyData    zzzz

abcdef    MyData    zzzz

abcdef    MyData    zzzz

abcdef  MyData    zzzz

abcdef  MyData    zzzz

abcdef MyData    zzzz

aa bb cc

aa  bb cc

aa bb  cc

aaa bb  cc

aaa  bb cc

];

SpaceMap:

MAPPING LOAD Repeat(' ',IterNo()+1) , ' '

While IterNo()<MaxSpaces;

LOAD Max(IterNo) as MaxSpaces;

LOAD IterNo() as IterNo

Resident tabStrings

While Index(string, Repeat(' ',IterNo())) or IterNo()=1;

Left Join (tabStrings)

LOAD Distinct

  string,

  SubField(MapSubString('SpaceMap', string),' ',2) as SubString2

Resident tabStrings;

hope this helps

regards

Marco

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

Clever Marco. But wouldn't you agree that

  AutoGenerate 9999

is easier to read and faster?

-Rob

MarcoWedel

Yes, indeed. Good point

Maybe it just proves that one could create a generic solution without assumptions,

even if it's not very practical for a productive solution ...

regards

Marco

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

I like your thinking.

-Rob

Not applicable
Author

Colin,

I do have to back of somewhat on my sweeping statement about eating delimiters.

I would like and expect a split / subfield command to treat consecutive 'space' delimiters as one delimiter, but I do not want the command to treat consecutive non-space delimiters (such as commas) as one delimiter.

JLR

Not applicable
Author

Peter,

Java, PHP, C, Perl, Python, etc ... all have a variation on the following:

    s.split(" +");

But they use a regular expression to split the string, which is not available to us in QV.


Not applicable
Author

re: Excel's trim - I did not know that. strange.  Not sure I like that. 
QV's trim functions as I expect - trim leading / trailing spaces and does nothing to the body of the string.

Not applicable
Author

Interesting - yet another way to fix the issue.  Thanks.

(And Rob, thanks for your "Cookbook".  It has been helpful).