How to find a string contains XXX-XXXXXX format? java [closed] - java

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a user input into a input box and want to find whether user entered the text format like 'XXX-XXXXXX'
How do I do this in java?

You could use split.
String str = "XXX-XXXXXX";
String[] words = str.split("-");
if(words[0].toCharArray().length == 3 && words[1].toCharArray().length == 6 && words.length == 2)
{
System.out.println("Correct");
}

Related

How to determine if a username is correct? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 months ago.
Improve this question
I need to determine if a username in the form of an email (something#something.com) is in the correct form. The necessary parameters for the username being correct are as follows:
there is something before the # symbol
there is text between the # symbol and the ".com"
the username ends in .com
These are the only parameters, if they are met the method will return true and if they are all not met it will return false.
public static boolean isCorrectUsername(String username){
var atPosition = username.indexOf("#");
return atPosition > 0 && username.endsWith(".com") && username.length() > atPosition + 5;
}

Can you create a code in array form with this? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Write a Java program that keeps a number from the user and generates an integer between 1
and 7 and displays the name of the weekday.
Create a Strint array with all weekdays ({"Sunday", "Monday"...}) and than get the name by index like this:
int day = 2;
System.out.println(weekdays[day - 1]);//output Monday

How to take out the numbers from the String and eliminate those number and store the filtered String and print it in java [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
String txt = "d89%l++5r19o7W *o=1645le9H"
System.out.println(t.replace(/\\d{0,}/g,''));
Because i'm bored...
String txt = "d89%l++5r19o7W *o=1645le9H";
txt = txt.replaceAll("\\d", "")
System.out.println(txt);
This will all numerical charactors from string
System.out.println(string.replaceAll("\\d",""));

Replace all √num from a string java [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have a string that contains String q = "What's the value of √32 and √83?";, my problem is replacing √num with sqrt(32) and sqrt(83).
That means my string should output : -
What's the value of sqrt(32) and sqrt(83)
is it possible?
Use a regex replacement on the pattern √(\d+)\b, and replace with sqrt(...):
String q = "What's the value of √32 and √83?";
String output = q.replaceAll("√(\\d+)\\b", "sqrt($1)");
System.out.println(output);
This prints:
What's the value of sqrt(32) and sqrt(83)?

Insert comma to a string of numbers after specific numbers of digits [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have this number
6430134080234080234080200000000
and i want it in this form :
643,01,340802,340802,340802,00000000
My aim is to insert it to a database.
First off, you obviously don't have a number, but a string.
String s = "6430134080234080234080200000000";
You can format it like so:
String formatted = s.substring(0,3) + "," + s.substring(3,5) + "," ...
Note that this only works if the input string is of the same length.

Categories