刪除!是Ruby中的String類方法,用於執行刪除操作,返回給定的字符串,如果未修改給定的字符串,則返回nil。
用法: str.delete!(parameter_list)
參數:在這裏,str是給定的字符串,parameter_list是指定的字符。
返回:如果未修改字符串,則為nil。
範例1:
# Ruby program to demonstrate
# the delete! method
# Taking a string and
# using the method
str = "String Counting"
puts str.delete! "ing"
輸出:
Str Cout
範例2:
# Ruby program to demonstrate
# the delete! method
# Taking a string and
# using the method
str = "String Counting"
puts str.delete! "ing", "^n"
str2 = "Ruby Method"
puts str2.delete! "ZXC"
輸出:
Strn Countn
相關用法
- Ruby String delete()用法及代碼示例
- Scala String ===用法及代碼示例
- Scala String ==用法及代碼示例
- Ruby String chr用法及代碼示例
- Scala String =~用法及代碼示例
- Ruby String eql?用法及代碼示例
- Ruby String hex用法及代碼示例
- Scala String +用法及代碼示例
- Ruby String byteslice用法及代碼示例
- Ruby String bytes用法及代碼示例
- Ruby String chars()用法及代碼示例
- Ruby String inspect用法及代碼示例
注:本文由純淨天空篩選整理自Kirti_Mangal大神的英文原創作品 Ruby | String delete! Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。