hi,
i want to seperate float point number in my string,for example
String str="ABCD23.50";
i want float number 23.50 from above string .I tried with regex patterns ,but
i didn't find a right solution .plaese help me .:o
Printable View
hi,
i want to seperate float point number in my string,for example
String str="ABCD23.50";
i want float number 23.50 from above string .I tried with regex patterns ,but
i didn't find a right solution .plaese help me .:o
Can you show your code?
Is that format is fixed, four letters before the decimal number?
Iam Giving Completete Requirement Of My Program .
I Have A String Like "abcd~ef~25.40..gh??"
Now My Aim Is To Convert Above String ,in Such A Way That All Special
Characters From The String ,except A Dot(.) Character That Exists
Between Numbers.finally My Desired Strig Should Look Like
"abcdef25.40gh".this Is My Problem.please Help Me It Is Urgent
Don't capitalize each word, or say its urgent please. That message wasn't very clear, do you want to remove all special character except . ?
-MK12
As I said earlier show that what you have done. In two posts you are explaining about two things.
Thank u for your valuable suggestion and please excuse me for my mistakes .My requirement is to remove special characters from a string ,but whenever I find a 'dot' charcter between numbers it should not be affected.An example of my
my requirement is
String str="abcd~...$..123.456..efgh
my output should look like this
str=abcd123.456
I tried with regex patterns ,but i am new to regex expressions, I am unable to understand difficult regex expressions.Please help me.
Thank u.
There are many dots in there.. whats special about the red one, and why shouldn't it also output the letters after?Quote:
String str="abcd~...$..123.456..efgh
-MK12
You can use regular expressions if you the know the exact pattern in general. Don't confused on it, exact not means the same thing, same order.
Or else in simple way, you can check each character either special one or not you are looking.
If I understood correctly.There may be a simpler and/or more efficient regex that does the job.Code:public class SpecialCharacterRemover {
public static void main(String[] args) {
String input = "abcd~ef~25.40..gh??";
String regex = "[^\\p{Alnum}.]|((?<!\\d)\\.)|(\\.(?!\\d))";
String output = input.replaceAll(regex, "");
System.out.println("==>" + output + "<==");
}
}
db
No db, this is fine. But the thing is our thread starter can confuse on how to build that regular expression. Lets him to ask question here on your code, so later you can comment on that. :)
thank u darryl your code is working for me,but you missed one case for me.As eranga said i don't know even basics of regular expression.I know it is a strange requirement.It is better to tell the reason for this requirement.my module includes the removing the duplicate entries in the database.
For example while entering the data manually,a person enter the string data "ABCD~12.50~",by mistake another person enter the same data like this
"ABCD~.12.50~" ,these problems are quite common.For these two strings table generates two auto increamented primary keys.But while retriveving the data problems araises because we mostly depends on primary key.For such cases i need to remove duplicate entries.First i used the simple regex pattern like this [^a-zA-Z0-9] to remove the special cahracters from the two strings and i compared two for duplicates ,but in later cases i faces the problems like "ABCD~25.30~" and "ABCD~2530~" ,these two are different and may not be same ,because 25.30 and 2530 may not be a data entry problem ,for this situtations i used very bad algoritham like this
1) finding 'dot' character in evering string
2) checking if '.' characters exists between two numbers ,based on this condition ,i performed
actions what i required.
But it is very bad way to write like this ,it consumes time,because of this reason iam not happy to show my code.
This reason pushed me to use "regex patterns".
I hope all of you understand my requirement,i feel very happy if you tell mistakes what i had done or if u tell a better solution.
If you are not much keen on regular expressions, my opinion is work on in basis way. As I said earlier go through the each character of the string and search for the special character you want to remove. Manipulate the new string avoiding those.