In Java, str=str.replaceAll("\\W", " ");
what does the \\ and W means ? Thank you !
Hi,Let me know if you need more information:-
===========================================
StringReplace.java
============================================
public class StringReplace {
public static void main(String[] args) {
String str = new String(
"__ a ! . 1 élève BCD GOÄ_432
GOÄ_432 ; : - ఆది - A a gefräßig gefräßig gefrä GHD \\W ` ~ @ # $ %
^ & * ( ) - _ + = ] [ { } \\ | ");
String str1 = new
String(str);
System.out.println(str);
str = str.replaceAll("\\W",
"|NONWORD|");
// --> \W means A non word
character
System.out.println("[" + str +
"]");
System.out.println();
// --> \w matches word
characters
str1 = str1.replaceAll("\\w",
"|WORD|");
System.out.println("[" + str1 +
"]");
// --> \ means you are
skipping character next to it.
String str3 = "\\5\\7"; // Here
actual string value is --> \\5\\7
System.out.println("\5\6");
System.out.println("Actual:"+str3);
// to skip the values you are
mentioning \ before \5 and \7
String replace = "\\\\";
System.out.println(replace);
str3 = str3.replaceAll("\\\\",
"-");
// the actual value i want to
replace in the above string is --> \ so i
// am giving \\
// now \5\7 will become -->
-5-7
System.out.println("Value: " +
str3);
// Description:
// \ --> escape character in
java Strings.
}
}
==============================================
OUTPUT:-
================================================
__ a ! . 1 élève BCD GOÄ_432 GOÄ_432 ; : - ఆది - A a
gefräßig gefräßig gefrä GHD \W ` ~ @ # $ % ^ & * ( ) - _ + = ]
[ { } \ |
[__|NONWORD|a|NONWORD||NONWORD||NONWORD||NONWORD||NONWORD|1|NONWORD||NONWORD|l|NONWORD|ve|NONWORD|BCD|NONWORD|GO|NONWORD|_432|NONWORD|GO|NONWORD|_432|NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD|A|NONWORD|a|NONWORD|gefr|NONWORD||NONWORD|ig|NONWORD|gefr|NONWORD||NONWORD|ig|NONWORD|gefr|NONWORD||NONWORD|GHD|NONWORD||NONWORD|W|NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD|_|NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD||NONWORD|]
[|WORD||WORD| |WORD| ! . |WORD| é|WORD|è|WORD||WORD|
|WORD||WORD||WORD| |WORD||WORD|Ä|WORD||WORD||WORD||WORD|
|WORD||WORD|Ä|WORD||WORD||WORD||WORD| ; : - ఆది - |WORD| |WORD|
|WORD||WORD||WORD||WORD|äß|WORD||WORD|
|WORD||WORD||WORD||WORD|äß|WORD||WORD| |WORD||WORD||WORD||WORD|ä
|WORD||WORD||WORD| \|WORD| ` ~ @ # $ % ^ & * ( ) - |WORD| + = ]
[ { } \ | ]
Actual:\5\7
\\
Value: -5-7
=====================================================
===========================================
Thanks
In Java, str=str.replaceAll("\\W", " "); what does the \\ and W means ? Thank you !
What value does this Processing code store in the s variable? String str = ""; int[] a = {4, 8, 7, 8}; for (int i = 0; i < a.length; i++) { str = a[i] + str; } String s = str;
What does this code do? On the flipside of this paper, write the same code in Java. #include <stdio.h> #include <stdlib.h> int main ) ( char *str: (char *) malloc (15) ; str strcpy (str, "Iron"); printf("String 8u\n", str, str); Address %s, (char ) realloc (str, 25); str strcat (str, "Maiden"); Su\n", str, str): Address %s, printf ("String free (str) return (0); What does this code do? On the flipside of this paper, write the same code in Java. #include...
JAVA CODE String[] str = in.nextLine().split("\\s"); for(int i=0;i<=str.length;i++){ if (str[i].equals(stop)) break; if(i%2==0){ System.out.print(str[i]+" "); } } lets say the INPUT for the array is: girl, boy, man, woman, girl, man, boy i dont want the array to print any string twice, i want the output to be like this: print all of them but print each once ---------- OUTPUT: girl, boy, man, woman
What does capitalizing bye do in this code? str='good-BYE' print (str.capitalize())
You need to write a program (one java class containing Main calling function isPalindrome (String str). The function isPalindrome (returns Boolean T/F) needs to determine whether or not a string is a palindrome, using recursion. The algorithm to check whether a string is a palindrome is shown below: /* check for first and last char of String: * if they are same then do the same thing for a substring * with first and last char removed. and carry on...
2. Prove that abSearch returns ?1 if str does not contain “ab” as a substring. You may omit the base case for this proof (done in problem 1). Hint: you will need to think carefully about the different cases of the if statement in lines 15–23 to show that abSearch always returns ?1 when str doesn’t contain “ab.” Answer the following questions about the algorithm below, which searches an input string for the substring "ab" and returns where "ab" first...
1. What does the word professional impression means to you in relationship to a healthcare professional? What does the book sugest is a Rood way to handle making a mistake? Do you agree or disagree? Explain
Have the function wildcard(str) read str which will contain two strings separated by a space.The first string will consist of the following sets of characters: +, *, $ and {N} which is optional.The plus (+) character represents a single alphabetic character, the ($) character represents anumber between 1-9, and asterisk (*) represents a sequence of the same character of length 3unless it is followed by {N} which represents how many characters would appear in thesequence where N will be at...
Hello, please help me with the follpowing question in java, thank you in advance
If you have private-ownership rights to something, what does this mean? O It means that you can transfer, sell, or mortgage the good. O It means that you have the right to do anything vou want with the good O It means that you pald for the good O It means that you have the right to infringe on the rights of ochers Evaluate the foliowinG statem nt about how private ownershp nnuences he i centive ๙ ntivduals to deve...