Stripping off the null at the end of a string.

Stripping off the null at the end of a string.

Post by Chri » Fri, 09 Nov 2001 11:55:55



Hi,
I was windering if there was a way to strip off the invisible null at the
end of a string.
Lets say I have taken a string and split it into individual components.
ie: i am canadian
var1 = i
var2 = am
var3 = canadian\0
How do I get rid of the \0 at the end of canadian???
Any help would be great!
Cheers,
Chris
 
 
 

Stripping off the null at the end of a string.

Post by Rich Tee » Fri, 09 Nov 2001 12:41:37



> Hi,
> I was windering if there was a way to strip off the invisible null at the
> end of a string.
> Lets say I have taken a string and split it into individual components.
> ie: i am canadian
> var1 = i
> var2 = am
> var3 = canadian\0
> How do I get rid of the \0 at the end of canadian???
> Any help would be great!

I don't think you're understanding C strings: ALL strings in C
are NUL terminated, by definition.  In other words,
var1 = i\0
var2 = am\0
var3 = canadian\0

--
Rich Teer

President,
Rite Online Inc.

Voice: +1 (250) 979-1638
URL: http://www.rite-online.net

 
 
 

Stripping off the null at the end of a string.

Post by Chri » Sat, 10 Nov 2001 07:06:56




> > Hi,
> > I was windering if there was a way to strip off the invisible null at
the
> > end of a string.
> > Lets say I have taken a string and split it into individual components.
> > ie: i am canadian
> > var1 = i
> > var2 = am
> > var3 = canadian\0
> > How do I get rid of the \0 at the end of canadian???
> > Any help would be great!

> I don't think you're understanding C strings: ALL strings in C
> are NUL terminated, by definition.  In other words,
> var1 = i\0
> var2 = am\0
> var3 = canadian\0

> --
> Rich Teer

> President,
> Rite Online Inc.

> Voice: +1 (250) 979-1638
> URL: http://www.rite-online.net

I actually do understand c strings. Its just that I formated the strings
differently... it ended up adding an extra char at the end of my last var
that I mistook for NULL.
Its all good.
Thanks anyways,
Chris
 
 
 

Stripping off the null at the end of a string.

Post by David Schwart » Wed, 14 Nov 2001 04:24:07



> I was windering if there was a way to strip off the invisible null at the
> end of a string.
> Lets say I have taken a string and split it into individual components.
> ie: i am canadian
> var1 = i
> var2 = am
> var3 = canadian\0
> How do I get rid of the \0 at the end of canadian???
> Any help would be great!

        This is like trying to cut the end off of a rope.

        DS

 
 
 

1. Stripping trailing blanks in a string.

This works for me:

sed -e 's/ *$//'

Cheers,
Zoran
--
char *Disclaimer = "My opinions only. Use at your own risk.";
char *Murphy =  "NON-RECIPROCAL LAWS OF EXPECTATIONS:"
                "  Negative expectations yield negative results."
                "  Positive expectations yield negative results.";

2. Lots of questions about tux and kernel setup

3. Stripping off path names: "find" and variables

4. EZPPP Problems

5. Stripping ^M off ftp, binary transfered files

6. Samba: How to join an NT domain?

7. stripping off control characters

8. Scientific Graphics Library for live graphics

9. Stripping off extensions for decompress() function

10. Strip off last character

11. Linux stripping off VLAN header

12. stripping bits off enviroment variables: $FILE

13. why spaces stripped off ??