473,399 Members | 4,177 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

String Help (Handeling filenames strings)

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.
Jul 20 '07 #1
2 1207
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
Jul 20 '07 #2
Daniel Marohn wrote:
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+\.

:)

--
Göran Andersson
_____
http://www.guffa.com
Jul 21 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Hannu Kankaanp?? | last post by:
This may be a bug or simply a strange result of undefined behaviour, but this is what I get with Python 2.3.2 on Windows XP: >>> import os >>> os.listdir('') >>> os.listdir(u'')
5
by: Edward K. Ream | last post by:
Am I reading pep 277 correctly? On Windows NT/XP, should filenames always be converted to Unicode using the mbcs encoding? For example, myFile = unicode(__file__, "mbcs", "strict") This...
0
by: C. Barnes | last post by:
Summary: Sorts strings in a way that seems natural to humans. If the strings contain integers, then the integers are ordered numerically. For example, sorts into the order . Code:
4
by: Daniel Fudge | last post by:
I can't send a string from a dymanic array to a function. At the getpts function declarationon (line 14), I get the following error. "main.cpp(14) : error C2664: 'void __thiscall...
19
by: Erik Wikström | last post by:
First of all, forgive me if this is the wrong place to ask this question, if it's a stupid question (it's my second week with C++), or if this is answered some place else (I've searched but not...
23
by: Bonj | last post by:
what is the correct form of string concatenation in VB.NET, + or &? Both seem to work, but which is correct? I know it's + in C# and & in VB6, but which in VB.NET?
4
by: WaterWalk | last post by:
Hello, I'm currently learning string manipulation. I'm curious about what is the favored way for string manipulation in C, expecially when strings contain non-ASCII characters. For example, if...
3
by: Torsten Bronger | last post by:
Hallöchen! I'd like to map general unicode strings to safe filename. I tried punycode but it is case-sensitive, which Windows is not. Thus, "Hallo" and "hallo" are mapped to "Hallo-" and...
4
by: shariquehabib | last post by:
Hi All, I am using file handeling in C lang. Can anyone please let me know that how can i read spaces from a perticular file?? To read some values (strings) i m using fscanf func. Can...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.