+ 1

How to delete something in the string?

i have string. for example my = "kitten" how can i delete "e" in that string... then my string will be my = "kittn" without make a new string...

9th Dec 2017, 2:05 AM
Razka Agniatara
Razka Agniatara - avatar
5 Respostas
+ 7
my = my[:4] + my[5:]
9th Dec 2017, 2:11 AM
ChaoticDawg
ChaoticDawg - avatar
9th Dec 2017, 2:10 AM
Hatsy Rei
Hatsy Rei - avatar
+ 8
public String missingChar(String str, int n) { String sub1= str.substring(0,n); String sub2= str.substring(n+1, str.length()); return sub1+sub2; } or public String missingChar(String str, int n) { StringBuffer buff= new StringBuffer(str); buff.delete(n,n+1); return buff.toString(); } you can do that by converting string into character array public class Practice {   public static String missingChar(String s, int index) { return new StringBuilder(s).deleteCharAt(index).toString(); }   public static void main(String[] args) { assert "ktten".equals(missingChar("kitten", 1)); assert "itten".equals(missingChar("kitten", 0)); assert "kittn".equals(missingChar("kitten", 4)); }   }
9th Dec 2017, 2:13 AM
GAWEN STEASY
GAWEN STEASY - avatar
+ 6
in python import re my1=''.join(re.findall("[^e]","kitten")) print(my1)
9th Dec 2017, 2:12 AM
Aravind Shetty
Aravind Shetty - avatar
+ 4
If you want to remove another letter or a string replace ^e with ^(whatever you want to remove)
9th Dec 2017, 2:14 AM
Aravind Shetty
Aravind Shetty - avatar