字符串中空格替换为%20(算法)
来源:互联网 发布:浩浩乎如冯虚御风的乎 编辑:程序博客网 时间:2024/05/28 05:13
Write a method to replace all spaces in a string with %20
1.Count the number of spaces during the first scan of the string
2.Parse the string again from the end and for each character
>> If a space is encountered.store "%20"
>> Else.store the character as it is in the newly shifted location
public static void ReplaceFur(char[] str, int length){int spaceCount = 0;int newLength,i = 0;for(i = 0; i < length; i++){if(str[i] == ' '){spaceCounter++;}}newLength = length + spaceCounter * 2 ;str[newlength] = '\0';for( i = length - 1; i >= 0; i--){if(str[i] == ' '){str[newlength -1] = '0';str[newlength -2] = '2';str[newlength -3] = '%';newlength -= 3;}else{str[newlength -1] = str[i];newlength -= 1;}}}
0 0
- 字符串中空格替换为%20(算法)
- 把字符串中空格替换为"%20"
- 替换字符串中空格为%20
- 替换空格(将字符串中的空格替换为20%)
- 替换字符串中空格算法
- 剑指offer - 将字符串中空格替换为20%
- 字符串替换空格算法
- 算法-字符串替换空格
- 剑指offer面试题:替换空格(将字符串每个空格替换为%20)
- 《剑指Offer》替换空格(将字符串中的空格替换为%20)
- 《剑指Offer》替换空格(将字符串中的空格替换为%20)
- 程序员面试金典(3)字符串中空格替换为"%20"
- 1.5-替换字符串中的空格为%20
- 将字符串中的空格替换为“20%”
- 替换字符串中的空格为%20--20150925
- 替换字符串中的空格为%20
- 把字符串中的空格替换为"%20"
- 将字符串中的空格替换为%20
- Linux中断(interrupt)子系统之二:arch相关的硬件封装层
- 实现长按计时
- 二、armv7 fedora7 SAMBA搭建
- 2015.3.11
- 彩色图片转黑白
- 字符串中空格替换为%20(算法)
- SqlServer 列转行 行转列 强大的SQLsever 博客
- Xcode 插件失效的临时解决方案
- Android实现垂直型的SeekBar
- 使用UItableview完成一个简单的QQ好友列表(二)
- CSS背景颜色透明
- web的情人节(我待你如初恋,你却虐我千百遍)
- MarkDown语法
- C 语言中switch语法的用处