Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Removing zeros at the start of a string

zeolitezeolite Member Posts: 78
Suppose I am given variables which represents numbers, e.g.:

[B]A=12345
B=01234
C=00123[/B]

How can I ensure that all zeros are removed from the start, so that
[CODE]echo $A
echo $B
echo $C[/CODE]produces the following output:
[B]12345
1234
123[/B]

Thanks in advance.

Comments

  • XfactorXfactor Member Posts: 343
    : Suppose I am given variables which represents numbers, e.g.:
    :
    : [B]A=12345
    : B=01234
    : C=00123[/B]
    :
    : How can I ensure that all zeros are removed from the start, so that
    : [CODE]echo $A
    : echo $B
    : echo $C[/CODE]produces the following output:
    : [B]12345
    : 1234
    : 123[/B]
    :
    : Thanks in advance.

    What language are you using? Is it bash, perl, php, etc... ?
  • The.ShaileshThe.Shailesh Member Posts: 19
    : : Suppose I am given variables which represents numbers, e.g.:
    : :
    : : [B]A=12345
    : : B=01234
    : : C=00123[/B]
    : :
    : : How can I ensure that all zeros are removed from the start, so that
    : : [CODE]echo $A
    : : echo $B
    : : echo $C[/CODE]produces the following output:
    : : [B]12345
    : : 1234
    : : 123[/B]
    : :
    : : Thanks in advance.
    :
    : What language are you using? Is it bash, perl, php, etc... ?
    :


    if u r using C then simplest way is to convert it to int then reconvert it to string this will remove all zeros from the start the functions are atoi and itoa respectively.
Sign In or Register to comment.