Can anyone suggest a nice way to trim any leading zeros off of a string,
e.g., I'd like to take a string like 00000012 and convert it to 12.
Ta
pemo 22 2116
How so?
<us******@gmail .com> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.com... just use printf is ok
pemo <us***********@ gmail.com> wrote: Can anyone suggest a nice way to trim any leading zeros off of a string, e.g., I'd like to take a string like 00000012 and convert it to 12.
strspn(..., "0") ?
--
Stan Tobias
mailx `echo si***@FamOuS.Be dBuG.pAlS.INVALID | sed s/[[:upper:]]//g`
pemo wrote: Can anyone suggest a nice way to trim any leading zeros off of a string, e.g., I'd like to take a string like 00000012 and convert it to 12.
Ta
pemo
char *s_ini="0000001 2";
char *s_final=s_ini;
while (*s_final=='0') s_final++;
S.Tobias <si***@famous.b edbug.pals.inva lid> wrote: pemo <us***********@ gmail.com> wrote: Can anyone suggest a nice way to trim any leading zeros off of a string, e.g., I'd like to take a string like 00000012 and convert it to 12.
strspn(..., "0") ?
size_t loc=strspn( mystring, "0" );
memmove( mystring, mystring+loc, strlen(mystring +loc)+1 );
--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
if string consists 0's in between the characters,
we can't use strspn.
right
gladiator <gl********@gma il.com> wrote: if string consists 0's in between the characters, we can't use strspn.
Sure you can. strspn() returns the number of characters spanned at
the beginning of the string it is passed that match the charset.
Characters matching charset at any other point in the string are
completely inconsequential .
--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
Thank you for clarification
pemo wrote: Can anyone suggest a nice way to trim any leading zeros off of a string, e.g., I'd like to take a string like 00000012 and convert it to 12.
Ta
pemo
sprintf(mystrin g, '%d", strtol(mystring , 0, 10))
....:==)
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =---- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Simon |
last post by:
Hi,
I have written a function to trim char *, but I have been told that my way
could be dangerous and that I should use memmove(...) instead.
but I am not sure why my code could be 'dangerous' or even why there could
be a problem.
here is the code
////////
|
by: Alex Vassiliev |
last post by:
Hi all.
Just wanted to share two handy RegEx expressions to strips leading and
trailing white-space from a string, and to replace all repeated spaces,
newlines and tabs with a single space.
* JavaScript example:
String.prototype.trim = function() {
// Strip leading and trailing white-space
|
by: Robert Mark Bram |
last post by:
Hi All,
I am using the following trim function:
function trim (str) {
return str.replace(/^\s*/g, '').replace(/\s*$/g, '');
}
The problem is that this doesn't trim instances of the " " char -
the non breaking space. Can this be represented in a grep statement at
|
by: FlyerN87 |
last post by:
For some reason this command will not trim the names shown in the
fields listed. I'm trying to do this in a text box on a report. I've
done this fairly succesfully in other reports but I must have done
something wrong here....
I've tried both of these...
=Trim( & )
=Trim( &", "& )
|
by: Darren Anderson |
last post by:
I have a function that I've tried using in an if then statement and I've
found that no matter how much reworking I do with the code, the expected
result is incorrect.
the code:
If Not (strIn.Substring(410, 10).Trim = "") Then
'Something processed
Else
'Something processed
| |
by: Sascha Herpers |
last post by:
Hi,
what is the difference between the trim function and the trim
String-member?
As far as I see it, both return the trimmed string and leave the
original string unaltered.
Is any of the two faster? Is there a general rule/opinion to prefere
members over functions?
Thanks for any hint.
|
by: Terry Olsen |
last post by:
I have an app that makes decisions based on string content. I need to make
sure that a string does not contain only spaces or newlines. I am using the
syntax 'Trim(String)" and it works fine. I thought I'd change it to the VB
..NET method "String.Trim" but that throws an object exception.
Which brings the question: is it compliant to use Trim(String), or is it
more within etiquette to use If Not String Is Nothing Then String.Trim?
|
by: arsaral |
last post by:
Hi,
Here is an extension of MSDN's trim right example to trim left-right...
First subroutines then the calling structure is given below...
Cheers.
Ali Riza SARAL
//*************************************************************
|
by: rkk |
last post by:
Hi,
I've written a small trim function to trim away the whitespaces in a
given string. It works well with solaris forte cc compiler, but on
mingw/cygwin gcc it isn't. Here is the code:
char *trim(char *s)
{
char *begin,*end;
begin = s;
|
by: Keith Thompson |
last post by:
Kevin Smith <no@spam.comwrites:
You posted this to microsoft.public.dotnet.languages.csharp, where I
presume it's topical. Why on Earth did you redirect followups to
comp.lang.c?
Anyone else replying to Kevin Smith's article, please *ignore* the
Followup-To header and post only to the csharp group. Thanks.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |