如何去掉字符串中所有的空格、制表符和换行符?

请先 登录 后评论

1 个回答

Yingnan Wang

第一种方法:使用strip函数

第二种方法:使用regexReplace函数,配合正则表达式实现

regexReplace("abc \t 123 \n 456 789","\\s+","")

替换前效果

attachments-2022-08-JP4WyIrA62fef4b1f1170.png

替换后效果

attachments-2022-08-P5ubvt6O62fef4c18ab76.png


第二种方法:如果使用上述正则表达式无法去掉某些特殊的空白字符,可以将其print到控制台,复制粘贴的方式使用strReplace函数将其替换掉

参考链接:

regexReplace:https://www.dolphindb.cn/cn/help/FunctionsandCommands/FunctionReferences/r/regexReplace.html

strReplace:https://www.dolphindb.cn/cn/help/FunctionsandCommands/FunctionReferences/s/strReplace.html



请先 登录 后评论