Questions tagged [replaceall]

The replaceAll() method in Java is used to replace parts of a string using a regular expression.

The replaceAll() method in Java is used to replace parts of a string using a regular expression.

Note that in most languages, including Java, the String object is immutable. In other words, you can't change it. If you want a slightly different string value then you have to create a second object. For that reason, replaceAll() does not actually change the string being searched, but rather returns a new string that is the result of the specified search and replace actions.

780 questions
-2
votes
4 answers

Trying to replace and reversing the entire Alphabetical order in Java

I am trying to reverse the entire Alphabetical order A-Z --> Z-A. This is what I have so far. public class Program { public static voud main(String[] args) { String text = "Hi My name is Dave\n"; text = text.replaceAll("[a-z…
Parnak Dave
  • 1
  • 1
  • 3
-2
votes
2 answers

Removing whitespaces from string and removing them from char array

I have an input that recieves a String in java: "a a" (50 characters total, 2 letters and 48 whitespaces) when i tried replace("\\s++",""); or replaceAll("\\s+",""); removes the whitespaces, but…
-2
votes
2 answers

How can I remove specific special characters in java?

I'm beginner in Java and it's still very complicated to understand how a regex works. I don't know how to create a regex to check and remove some specific special characters from a string. "!@#$%¨&*()_-+={[}]º|\,.:;?/° (I need check and remove it…
F4bioo
  • 179
  • 1
  • 5
  • 11
-2
votes
2 answers

Could please let me know the Explanation s.replaceAll("\\S", " ")

String s="Swamy Application"; s=s.replaceAll("\\S"," "); system.out.println(s); Should return String but we are getting empty I need explanation What happening in \\S.
-2
votes
1 answer

String.replaceAll does not apply to any kind of characters

So what i've got is this simple method which should remove all characters except upper and lowercase letters and numbers from a string. public static String toSimple(String arg) //redurziert einen String auf Buchstaben und ganze Zahlen { String…
-2
votes
4 answers

Replacing multiple char from String with single space

I want to replace multiple character in given string with a single space. eg: He is a very very good boy, isn't he? Should be replaced to He is a very very good boy isn t he My code…
ra1vi2
  • 17
  • 6
-2
votes
3 answers

What is causing this StringIndexOutofBounds exception?

I have this code to find a palindrome below; I need to be able to remove all numbers, spaces, and punctuation from the user input String, so I've been using replaceAll. When I only had String input = str.toLowerCase(); and String newInput =…
Sarah Diri
  • 97
  • 1
  • 9
-2
votes
1 answer

Remove special character \

I'm using Java, and I want to remove all the occurrences of \ from my string (something like http\:\/\/news.investors\/092115\-772034\-red\-hat\-tops\-16\-views\-beat.html ) I'm using replace all but I don't know how is the regular expression to do…
Matteo Amadei
  • 67
  • 1
  • 4
-2
votes
1 answer

why Word.Application.Selection.Find.Execute does not work in footnote and endnote

why Word.Application.Selection.Find.Execute does not work in footnote and endnote? my code is: object wrap = WdFindWrap.wdFindContinue; object wdReplaceAll = WdReplace.wdReplaceAll; object text = findWhat; object replaceText = replaceWith; object…
Amir Niazi
  • 79
  • 8
-2
votes
3 answers

Replace substring with some math characters from String - java

I have a math expression looks like String st = "((3-(5-2))+(2*(5-1)))"; and I want to replaceAll (5-1) with 4 and after that replaceAll (2*4) with 8 and... I haven't problem with replacing (5-1) with 4 but when I received to (2*4), as it has * star…
Ehsan Solimo
  • 23
  • 1
  • 9
-2
votes
1 answer

String replace with integer not working

I have been working on some Java code and I came across a really weird error, Im trying to replace a piece of string with an Integer. Added all kinds of debugs but I cant seem to find it out. private void executeMsg() { value =…
Bram
  • 97
  • 8
-2
votes
2 answers

Replace single " (quotation mark)

How can I replace a single quotation mark " in a String in Java? Not the word inside a quote.
André Mathisen
  • 904
  • 2
  • 7
  • 15
-2
votes
3 answers

Remove all numbers and "{" from a String Array

I am trying to remove all non numeric characters from the String Array as require to compare it with the list of numbers. The split works but I am not able to compare the two Sets for(String w:a1) { w=w.replaceAll("[^\\d.]", ""); …
ananymous59
  • 200
  • 1
  • 14
-2
votes
3 answers

how to replace ' with " inside a String

I have a String containing: 'abc' 'abc' 'abc'. How can i use replaceAll, to produce: "abc" "abc" "abc" ? I tried using StringA=StringA.replaceAll(''','"');
Kumara
  • 117
  • 2
  • 10
-2
votes
3 answers

ReplaceAll Method

I want to replace "\" with this "/" in my string. I am using method replaceAll for this. But it is giving me error. String filePath = "D:\pbx_u01\apache-tomcat-6.0.32\bin\uploadFiles\win.jpg"; String my_new_str = filePath.replaceAll("\\", "//");
Fahad Murtaza
  • 256
  • 2
  • 9
  • 18