String Help (Handeling filenames strings)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Could someone give a hand on how to handle this issue: I need to find a way
of removing zeros from files names. The zeros in the names are used to sort
the file name, e.g. MAK0080.pci, MAK-0080.pci. What I need to do is to
remove the zeros, so the file names become MAK80.pci o MAK-80.pci. I have
done something in Visual Basic using the Mid() function and going thru the
string removing the zeros. Is there a better way of doing this, perhaps a
more reliable method, may be using Regex. Any help will be greatly
appreciated.
 
Hi!
string removing the zeros. Is there a better way of doing this, perhaps a
more reliable method, may be using Regex. Any help will be greatly
appreciated.

Well., I cannot say if this is more relyable (but I guess so), but regex
seems to be a good solution. The paddern would be
(?<firstpart>[^0]+)0+(?<secondpart>.+)

if the regex match, you can combine the two groups to the result.
Let me know, if you have problems with this, and I will post some lines of
code.

greets
Daniel
 
Daniel said:
Hi!
string removing the zeros. Is there a better way of doing this, perhaps a
more reliable method, may be using Regex. Any help will be greatly
appreciated.

Well., I cannot say if this is more relyable (but I guess so), but regex
seems to be a good solution. The paddern would be
(?<firstpart>[^0]+)0+(?<secondpart>.+)

Wouldn't that turn the filename "test105.txt" into "test15.txt"?
if the regex match, you can combine the two groups to the result.
Let me know, if you have problems with this, and I will post some lines of
code.

greets
Daniel

I would match the zeroes instead, so that they could be removed by
replacing:

\D(0+)\d+\.

:)
 
Back
Top