Quantcast
Channel: How do we remove special characters from a string from a particular position in java? - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Answer by ChivalrouS for How do we remove special characters from a string from a particular position in java?

$
0
0

For the replacement. You need to first get the content value of name field. Then you can remove special characters from the string.

Example code block:

    String line = "name=\"xyz =bcd .olm --=myname\"";    Pattern pattern = Pattern.compile("name=\"(.*)\"");    Matcher matcher = pattern.matcher(line);    if (matcher.find()) {        String nameString = matcher.group(1);        String newNameString = nameString.replaceAll("[^A-Za-z0-9 ]", "");        String result = line.replace(nameString, newNameString);        System.out.println(result);    }

Result prints as name="xyz bcd olm myname"


Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>