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.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()

    //Input Character to Remove from String
    print("Enter Character : ")
    val c = scanner.next()[0]


    //Replace character with Empty String
    val newStr=str.replace(c.toString(),"",ignoreCase = true)


    //Print String after Replacement
    println("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中判断字符串

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值