从字符串中删除前导零 [英] Removing leading zeroes from a string

查看:162
本文介绍了从字符串中删除前导零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串 0023525631 但我想要的是字符串 23525631 - 没有前导零。

解决方案

如果是数字,可以将字符串转换为整数,



声明指向此字符串的指针,并将此指针设置为字符串的开头,然后迭代你的字符串,并在字符串的开头添加这个指针数字的零。然后你有指向字符串的指针,从零开始,你必须使用指针obsain字符串没有零,如果你使用字符串你可以得到字符串与零。





您可以反转字符串,如果你得到一些 char!='0'你停止迭代否则你重写这个字符为null。之后,您可以反转字符串,以返回字符串中没有前导零的整数。


I have a string 0023525631 but what I want is the string 23525631 -- without the leading zeroes. How do I do this?

解决方案

You can convert string to integer and integer to string if you are number.

Or

Declarate pointer to this string and set this pointer to a start of your string, then iterate your string and add to this pointer number of zeros on the start of string. Then you have pointer to string who starting before zeros, you must use pointer to obitain string without zeros, if you use string you can get string with zeros.

Or

You can reverse string, and iterate it from reverse, if you get some char != '0' you stop iterating else you rewriting this char to null. After it you can reverse string to get back your integer in string without leading zeros.

这篇关于从字符串中删除前导零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆