当前位置:网站首页>String replace space
String replace space
2022-07-03 01:59:00 【A little sigh】
subject : One string space is enough , Replace each space in the string with "%20", Such as "He ll o" Replace with "He%20ll%20o"
Ideas : First traverse the string , Get the number of spaces , To get the length of the new string . Traverse the string from the end of the string , Copy characters one by one , Replace with... When a space is encountered %20.
#include <iostream>
void trimBlank(char arr[], int length)
{
if (arr == NULL || length <= 0) {
return;
}
int index = 0;
int blankNumber = 0;
while (arr[index]!= '\0') {
if (arr[index] == ' ') {
blankNumber++;
}
index++;
}
int replaceIndex = length + blankNumber * 2;
int i = length;
while (i >=0 && replaceIndex > i) {
if (arr[i] == ' ') {
arr[replaceIndex--] = '0';
arr[replaceIndex--] = '2';
arr[replaceIndex--] = '%';
} else {
arr[replaceIndex--] = arr[i];
}
i--;
}
}
int main(int argc, const char * argv[]) {
char a[20] = {'h', ' ', 'e','l','l', ' ', 'o'};
trimBlank(a, 7);
std::cout<<a<<std::endl;
return 0;
}
边栏推荐
- The testing process that software testers should know
- How is the mask effect achieved in the LPL ban/pick selection stage?
- Button button adaptive size of wechat applet
- Reprint some Qt development experience written by great Xia 6.5
- Network security ACL access control list
- 深度(穿透)选择器 ::v-deep/deep/及 > > >
- Wechat applet development tool post net:: err_ PROXY_ CONNECTION_ Failed agent problem
- Why can't the start method be called repeatedly? But the run method can?
- 缺少库while loading shared libraries: libisl.so.15: cannot open shared object file: No such file
- [error record] an error is reported in the fluent interface (no mediaquery widget ancestor found. | scaffold widgets require a mediaquery)
猜你喜欢
![[shutter] top navigation bar implementation (scaffold | defaulttabcontroller | tabbar | tab | tabbarview)](/img/f1/b17631639cb4f0f58007b86476bcc2.gif)
[shutter] top navigation bar implementation (scaffold | defaulttabcontroller | tabbar | tab | tabbarview)

ByteDance data Lake integration practice based on Hudi
![[fluent] fluent debugging (debug debugging window | viewing mobile phone log information | setting normal breakpoints | setting expression breakpoints)](/img/ac/bf83f319ea787c5abd7ac3fabc9ede.jpg)
[fluent] fluent debugging (debug debugging window | viewing mobile phone log information | setting normal breakpoints | setting expression breakpoints)

STM32 - GPIO input / output mode

Rockchip3399 start auto load driver
![[fluent] hero animation (hero animation use process | create hero animation core components | create source page | create destination page | page Jump)](/img/68/65b8c0530cfdc92ba4f583b0162544.gif)
[fluent] hero animation (hero animation use process | create hero animation core components | create source page | create destination page | page Jump)
![[North Asia data recovery] data recovery case of raid crash caused by hard disk disconnection during data synchronization of hot spare disk of RAID5 disk array](/img/2a/98400b0d0b5eda1e52abae30746f2b.jpg)
[North Asia data recovery] data recovery case of raid crash caused by hard disk disconnection during data synchronization of hot spare disk of RAID5 disk array

Everything file search tool
![[shutter] animation animation (animatedbuilder animation use process | create animation controller | create animation | create components for animation | associate animation with components | animatio](/img/32/fa1263d9a2e5f77b0434fce1912cb2.gif)
[shutter] animation animation (animatedbuilder animation use process | create animation controller | create animation | create components for animation | associate animation with components | animatio

Ni visa fails after LabVIEW installs the third-party visa software
随机推荐
Socket编程
Problems encountered in small program development of dark horse shopping mall
[data mining] task 2: mimic-iii data processing of medical database
Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance o
A 30-year-old software tester, who has been unemployed for 4 months, is confused and doesn't know what to do?
Machine learning notes (constantly updating...)
[error record] an error is reported in the fluent interface (no mediaquery widget ancestor found. | scaffold widgets require a mediaquery)
Vant implements a simple login registration module and a personal user center
STM32 - switch of relay control lamp
Anna: Beibei, can you draw?
浏览器是如何对页面进行渲染的呢?
网络安全-钓鱼
Ni visa fails after LabVIEW installs the third-party visa software
Custom components, using NPM packages, global data sharing, subcontracting
自定义组件、使用npm包、全局数据共享、分包
502 (bad gateway) causes and Solutions
网络安全-浅谈安全威胁
Wechat applet Development Tool Post net:: Err Proxy Connexion Problèmes d'agent défectueux
The technology boss is ready, and the topic of position C is up to you
网络安全-动态路由协议RIP