如何使字符串替换其中的特殊字符 [英] How Do I Make A String Replacing Special Characters In It

查看:102
本文介绍了如何使字符串替换其中的特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串12,000我需要12000和12.78到1278而不是两个单独的字符串12和78.

请帮帮我。



在此先感谢。

I have a string 12,000 i need it to be 12000 and 12.78 into 1278 instead of two separate string 12 and 78.
Please do help me.

Thanks in advance.

推荐答案

好的...首先你需要确定你输入的字符串:因为你必须处理它们不一样。

替代方案是:总是删除逗号并拆分字符串......所以我们会看一下。

但是......这听起来像是你的作业,所以我会让你写代码!

这并不复杂:

1)分配两个字符串,每个字符串足以容纳整个输入。 (所以如果没有什么可以删除,你只需继续复制即可。)

2)通过输入前进,将每个字符复制到第一个输出 - 除非它是逗号,其中案件不要复制它。当你到达字符串的末尾或句号时,停止。

3)通过输入的其余部分(如果有的话)前进,将其复制到第二个输出,直到结束。



完成!
Ok...first you need to decide which string you have as input: because you will have to process them differently.
The alternative is: always remove the commas and split the string...so we will look at that.
But...this sounds like your homework, so I'll let you write the code!
It's not complex:
1) Allocate two strings, each big enough to hold the whole input. (So if there is nothing to remove, you just keep going and copy it all.)
2) Advance through the input, copying each character to the first output - unless it is a comma, in which case don't copy it. When you hit the end of the string, or a period, stop.
3) Advance through the rest of the input (if any), copying it to the second output, untiul you reach the end.

Done!


这篇关于如何使字符串替换其中的特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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