kotlin 字符串去空格

Given a string, we have to remove all whitespaces from it.

给定一个字符串,我们必须从中删除所有空格。

Example:

例:

    Input:
string = "Hello world!"
Output:
"Helloworld!"

在Kotlin中从字符串中删除所有空格的程序 (Program to remove all whitespaces from the string in Kotlin)

In this program, at first, we are reading a string and them replacing all whitespaces using the replace() function.

首先,在此程序中,我们正在读取一个字符串,并使用replace()函数替换所有空白。

package com.includehelp.basic
import java.util.*
//Main Function, entry Point of Program
fun main(args: Array<String>) {
// InputStream to get Input
val scanner = Scanner(System.`in`)
//Input String
print("Enter String : ")
var str = scanner.nextLine()
//Replace character with Empty String
val newStr=str.replace("\\s".toRegex(),"")
//Print String after Replacement
println("String after Removed WhiteSpaces : $newStr ")
}

Output

输出量

Run 1:
Enter String : Hello includehelp how are you ?
String after Removed WhiteSpaces : Helloincludehelphowareyou?
---
Run 2:
Enter String : Covid -19 [pandimic spread all over the world
String after Removed WhiteSpaces : Covid-19[pandimicspreadallovertheworld

翻译自: https://www.includehelp.com/kotlin/remove-all-whitespaces-from-the-string.aspx

kotlin 字符串去空格

kotlin 字符串去空格_Kotlin程序从字符串中删除所有空格相关推荐

  1. C语言—数组,给定如下的数组: char chars[] = { ‘a‘, ‘ ‘, ‘b‘, ‘ ‘, ‘c‘, ‘ ‘, ‘ ‘, ‘d‘ } ;写一个程序将数组中所有的空格字符替换为下划线字符‘

    给定如下的数组:   char chars[] = { 'a', ' ', 'b', ' ', 'c', ' ', ' ', 'd' } ; 写一个程序将数组中所有的空格字符替换为下划线字符'_'. ...

  2. scala 去除重复元素_Scala程序从列表中删除重复项

    scala 去除重复元素 List in Scala is a collection that stores data in the form of a liked-list. The list is ...

  3. kotlin创建静态单利_Kotlin程序来计算单利

    kotlin创建静态单利 Given, principal, rate, and time, we have to calculate the simple interest. 给定本金,利率和时间, ...

  4. linux 有空格的文件夹,Linux之删除带有空格的文件

    导读 这篇文章主要介绍了Linux之删除带有空格的文件(不是目录),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧. 大家平时工作 ...

  5. Python | 程序从列表中删除范围内的所有元素

    Given a list and we have to remove elements in a range from the list in Python. 给定一个列表,我们必须从Python中的 ...

  6. kotlin中判断字符串_Kotlin程序查找字符串中字符的频率

    kotlin中判断字符串 Given a string and a character, we have to find the frequency of the character in the s ...

  7. kotlin 字符串_Kotlin程序确定字符串是否具有所有唯一字符

    kotlin 字符串 Given a string, we have to check whether it has all unique characters or not. 给定一个字符串,我们必 ...

  8. 字符串查找c语言程序,C语言中字符串处理小案例(查找)

    这一题超级麻烦,就算是使用java进行处理也不会很简单.而且如果是实际项目要考虑的情形非常多,这里只是一个简单实现 * 里面涉及到字符串查找,获取关键字符串,进制转换(进制转换未实现) * 而且字符指 ...

  9. kotlin半生对象_Kotlin程序| 随播对象特征

    kotlin半生对象 伴侣对象 (Companion object) If you need a function or a property to be tied to a class rather ...

最新文章

  1. 一种电磁铁磁场分析测量
  2. Java Spring源代码学习之DispatcherServlet.getHandler
  3. java GUI怎么输入_在Swing中创建Java GUI以进行表单输入
  4. 防删库实用指南 | 只需一步,快速召回被误删的表
  5. oracle 创建表空间 pcincrease,oracle建表空间
  6. 首发量产1亿像素,小米新机宣布11月5日发布!
  7. 2021年十大 web hacking 技术汇总
  8. 数字的眼光看世界(常见常量、数值大下)
  9. git untracked working tree files would be overwritten by merge
  10. 信号处理基础——傅里叶变换与短时傅里叶变换
  11. 关于南宁市教育云网站的网课视频链接blob加密破解
  12. 响应式布局——媒体查询
  13. android刷win8,驰为VX8 3G Win8刷安卓系统固件教程发布
  14. 用户权限---u+s\g+s\o+t三个特殊权限说明
  15. 加油站-问题详解(暴力-整体-贪心)
  16. Foxmail 去掉签名横线 Foxmail 去掉签名默认横线
  17. python三维立体画_用matplotlib创建三维立体图
  18. 在vue项目中使用echarts 阿星小栈
  19. 轻松禁用WinRAR设置
  20. 华为IT总监徐家骏的10年

热门文章

  1. 什么是msstdfmt.dll?如何解决相关问题?
  2. Java笔记二十二——设计模式
  3. CAD2:cad常用快捷命令 进入草图设置
  4. 使用Vue组件为页面添加评论
  5. Intellij idea用快捷键自动生成序列化id
  6. centos挂载硬盘时提示mount:unknown filesystem type 'LVM2_member'的解决方案
  7. 小米10至尊纪念版和iqoo5pro 的区别
  8. Kplayer for Mac(高清视频播放器)
  9. 骑战三国服务器维护,《骑战三国》4月26日进行全服停服更新
  10. 三国志2017攻略 服务器维护,三国志2017你想要的进阶攻略