Remove white space from string without using trim method?

后端 未结 5 1448
轮回少年
轮回少年 2021-01-27 12:10

given string is \'_home sweet home__\' if user enter the mode as 0 then o/p should be \'home sweet home__\' if user enter the mod

5条回答
  •  广开言路
    2021-01-27 12:23

    Do this to remove all the whitespaces. Then, subtract the length of the second string from the length of the first to determine the total number of whitespaces removed.

    If you want to remove only the preceding whitespace, use "^\\s+". To remove trailing, use "\\s+$".

提交回复
热议问题