kotlin中判断字符串_Kotlin程序删除字符串中所有出现的字符
生活随笔
收集整理的這篇文章主要介紹了
kotlin中判断字符串_Kotlin程序删除字符串中所有出现的字符
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
kotlin中判斷字符串
Given a string and a character, we have to remove all occurrences of the character in given string.
給定一個字符串和一個字符,我們必須刪除給定字符串中所有出現的字符。
Example:
例:
Input:string = "includeHelp Delhi"Output:String after removing character : "includeelp Deli"在Kotlin中刪除字符串中所有出現的字符的程序 (Program to remove all occurrences of a character in a string in Kotlin)
package com.includehelp.basicimport java.util.*//Main Function, entry Point of Program fun main(args: Array<String>) {// InputStream to get Inputval scanner = Scanner(System.`in`)//Input Stringprint("Enter String : ")var str = scanner.nextLine()//Input Character to Remove from Stringprint("Enter Character : ")val c = scanner.next()[0]//Replace character with Empty Stringval newStr=str.replace(c.toString(),"",ignoreCase = true)//Print String after Replacementprintln("String after removing character : $newStr ") }Output
輸出量
Run 1: Enter String : includeHelp Delhi Enter Character : h String after removing character : includeelp Deli --- Run 2: Enter String : corona virus global death rate Enter Character : o String after removing character : crna virus glbal death rate翻譯自: https://www.includehelp.com/kotlin/remove-all-occurrences-of-a-character-in-a-string.aspx
kotlin中判斷字符串
總結
以上是生活随笔為你收集整理的kotlin中判断字符串_Kotlin程序删除字符串中所有出现的字符的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java BigInteger类| 带实
- 下一篇: 哈密顿路径_检查图形是否为哈密顿量(哈密