+ 3

How to remove a desired part of string? (not using indexes)

3rd Sep 2020, 11:32 AM
Jeet Swarnakar
Jeet Swarnakar - avatar
3 Respuestas
+ 3
If you mean you for example want to subtract " world" from "Hello world!" so that you get "Hello!", you can use the replace method: Replacing " world" with an empty string: "Hello world!".replace(" world", "") ---> "Hello!" Replace method will by default replace all occurences of " world" with the empty string. You can prevent this by adding third argument, which represents how many occurences of " world" you want to replace. Replacing 2 occurences of " world" with an empty string: "Hello world world world!".replace(" world", "", 2) ---> "Hello world!"
3rd Sep 2020, 1:20 PM
Seb TheS
Seb TheS - avatar
+ 7
Jeet Swarnakar , what do you mean by saying 'subtract a part of a string'? It would be great if you could do a sample for us. Thanks.
3rd Sep 2020, 11:46 AM
Lothar
Lothar - avatar
+ 2
thanks Seb TheS....you got what i meant
3rd Sep 2020, 4:23 PM
Jeet Swarnakar
Jeet Swarnakar - avatar