Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
sroettger
Partner - Contributor III
Partner - Contributor III

Shorten string - search out value

Hello, I have a string with different file names at the end.
Once
D:\Data\3423.jpg
and then
D:\Data\999934.JPG
or also
D:\Data\4545.JPG

How can I get only the numerical value 3423, 999934 or 4545?
I have no more ideas!!!

Thank you very much and all the best!

Labels (1)
6 Replies
Vegar
MVP
MVP

If it is only digits and no digits in the folder structure then you can get the desired result by using keepchar()

Try this: KeepChar([Your string], '1234567890')

 

 

 

 

Vegar
MVP
MVP

You can also do the more generic solution fetching the name using subfield(subfield())

SubField(SubField([YourString], '\',-1),'.',1)

MarcoWedel

In case your directories might include numbers as well, you could use something like:

MarcoWedel_0-1645641023778.png

table1:
LOAD *,
     SubField(SubField(Path,'\',-1),'.',1) as Number
Inline [
Path
D:\Data\3423.jpg
D:\Data\999934.JPG
D:\Data\4545.JPG
D:\PathWithNumber6789\12345.JPG
];

 

hope this helps

Marco

sroettger
Partner - Contributor III
Partner - Contributor III
Author

Hi and thank you!

It  works with "SubField" - BUT,  what can I do, if I want the ImageFileName, like

3423.jpg

999934.jpg

or also 3343_3.jpg (new Case).

Than, SubField dosn't work. 

What can I do?

Iswarya_
Creator
Creator

Hi @sroettger 

Try like below:

SubField(Path,'\',-1)

Subfield will work even if it's new case like mentioned 3343_3.jpg

MarcoWedel

SubField() still would work to also implement this new requirement, but you could as well use Mid() and Index() to extract the string following the last '\' delimiter, i.e. the file name including extension:

 

MarcoWedel_0-1646170275784.png

table1:
LOAD *,
     SubField(Path,'\',-1) as File,
     Mid(Path,Index(Path,'\',-1)+1) as File2
Inline [
Path
D:\Data\3423.jpg
D:\Data\999934.JPG
D:\Data\4545.JPG
D:\PathWithNumber6789\12345.JPG
D:\Data\999934.jpg
D:\Data\3343_3.jpg
1234_5.jpg
];

 

hope this helps

Marco