Remove all spaces and punctuation (anything not a letter) from a string?

remove punctuation from string python regex
c program to remove punctuation from a string
replace punctuation with space python
remove punctuation from list python
remove unwanted characters from string python
remove punctuation from string java
python remove all punctuation and control characters
remove special characters and space from string python

In Java, how can I take a string as a parameter, and then remove all punctuation and spaces and then convert the rest of the letters to uppercase?

Example 1:

Input: How's your day going?

Output: HOWSYOURDAYGOING

Example 2:

Input: What's your name again?

Output: WHATSYOURNAMEAGAIN

This should do the trick

String mystr= "How's your day going?";
mystr = mystr.replaceAll("[^A-Za-z]+", "").toUpperCase();
System.out.println(mystr);

Output:

HOWSYOURDAYGOING

The regex [^A-Za-z]+ means one or more characters that do not match anything in the range A-Za-z, and we replace them with the empty string.

Removing punctuations from a given string, Given a string, remove the punctuation from the string if the given character is a check whether parsing character is punctuation or not traverse the given string and if any punctuation Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above. In Java, how can I take a string as a parameter, and then remove all punctuation and spaces and then convert the rest of the letters to uppercase? Example 1: Input: How's your day going?

String yourString = "How's your day going";
yourString=yourString.replaceAll("\\s+",""); //remove white space
yourString=yourString.replaceAll("[^a-zA-Z ]", ""); //removes all punctuation
yourString=yourString.toUpperCase(); //convert to Upper case

Remove all non-alphabetical characters of a String in Java?, The regular expression “\\W+” matches all the not alphabetical characters (​punctuation marks, spaces, underscores and special symbols) in a  Questions: I need to remove all special characters, punctuation and spaces from a string so that I only have letters and numbers. Answers: This can be done without regex: >>> string = "Special $#! characters spaces 888323" >>> ''.join(e for e in string if e.isalnum()) 'Specialcharactersspaces888323' You can use str.isalnum: S.isalnum() -> bool Return True

I did it with

inputText = inputText.replaceAll("\\s|[^a-zA-Z0-9]","");


inputText.toUpper();  //and later uppercase the complete string

Though @italhourne 's answer is correct but you can just reduce it in single step by just removing the spaces as well as keeping all the characters from a-zA-Z and 0-9, in a single statement by adding "or". Just a help for those who need it!!

How to Clean Text for Machine Learning with Python, How do I remove all punctuation from a string in Python? Remove punctuation. With the "in" operator and the string.punctuation constant, we can remove all punctuation chars from a string. Note: We add each character to our result that is not punctuation. Spaces (which are not punctuation) are kept.

Well, I did it the long way, take a look if you want. I used the ACII code values (this is my main method, transform it to a function on your own).

String str="How's your day going?";
    char c=0;
    for(int i=0;i<str.length();i++){
        c=str.charAt(i);
        if(c<65||(c>90&&c<97)||(c>122)){
            str=str.replace(str.substring(i,i+1) , "");
        }
    }
    str=str.toUpperCase();
    System.out.println(str);

How to remove all punctuation marks (comma, quotation , offers a function called translate() that will map one set of characters to another. 1) Iterate through all characters of given string, do following a) If current character is a space, then move all subsequent characters one position back and decrease length of the result string. Time complexity of above solution is O(n 2 ).

How to remove all special characters, punctuation and spaces from , How do I get rid of punctuation and spaces in Excel? This will remove any special characters from your text. It does occasionally miss some rare characters, but it does a pretty good job. Anytime you come across a character that isn't removed (should be rarely as I've included all the common ones), just add it somewhere in that string of symbols in the code. Functions are very handy.

How to discard all punctuation from a text file, marks from) into it, and then drag the Fill Handle to the range as you need. The COMPRESS function compresses the character value and removes all of the blank spaces from the string. Remove Selected Characters from Character Value You can also specify a character to be removed in the COMPRESS function.

Erase punctuation from text and documents - MATLAB , To remove all special characters, punctuation and spaces from string, iterate over the string and filter out all non alpha numeric characters. the first two arguments, source and chars. All characters that appear in the second argument are removed from the result. three arguments, source, chars, and modifier (s) The K modifier (specified in the third argument) determines whether the characters in the second argument are kept or removed from the result.

Comments
  • stackoverflow.com/questions/12734721/… and docs.oracle.com/javase/6/docs/api/java/lang/… just a start..
  • sounds like a combination of Regex and .toUpper() to me.
  • this sounds like a job for regular expressions
  • You can still kill off your 2nd line and have your regex handle all characters not in a-z and A-Z