Results 1 to 12 of 12
Thread: [SOLVED] problem with strings
- 02-20-2009, 10:35 AM #1
Member
- Join Date
- Feb 2009
- Posts
- 96
- Rep Power
- 0
- 02-20-2009, 11:56 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Can you show your code?
Is that format is fixed, four letters before the decimal number?
- 02-20-2009, 01:49 PM #3
Member
- Join Date
- Feb 2009
- Posts
- 96
- Rep Power
- 0
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
- 02-20-2009, 02:10 PM #4
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 . ?
-MK12Tell me if you want a cool Java logo avatar like mine and I'll make you one.
- 02-20-2009, 06:16 PM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
As I said earlier show that what you have done. In two posts you are explaining about two things.
- 02-21-2009, 06:05 AM #6
Member
- Join Date
- Feb 2009
- Posts
- 96
- Rep Power
- 0
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.Last edited by sandeepsai39; 02-21-2009 at 11:43 AM.
- 02-21-2009, 04:12 PM #7
There are many dots in there.. whats special about the red one, and why shouldn't it also output the letters after?String str="abcd~...$..123.456..efgh
-MK12Tell me if you want a cool Java logo avatar like mine and I'll make you one.
- 02-22-2009, 10:30 AM #8
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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.
- 02-22-2009, 04:03 PM #9
If I understood correctly.
There may be a simpler and/or more efficient regex that does the job.Java 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
- 02-23-2009, 06:01 AM #10
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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. :)
- 02-23-2009, 02:50 PM #11
Member
- Join Date
- Feb 2009
- Posts
- 96
- Rep Power
- 0
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.
- 02-23-2009, 04:59 PM #12
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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.
Similar Threads
-
comparing strings
By diggitydoggz in forum New To JavaReplies: 7Last Post: 12-23-2008, 04:40 AM -
Problem Comparing Strings (its not what you think)
By hilather in forum New To JavaReplies: 7Last Post: 11-19-2008, 06:43 PM -
Reading in strings
By thekermo in forum New To JavaReplies: 2Last Post: 10-19-2008, 05:24 PM -
characters + strings
By Gilgamesh in forum New To JavaReplies: 3Last Post: 03-02-2008, 09:10 PM -
Comparison of Strings
By Cero.Uno in forum New To JavaReplies: 3Last Post: 02-11-2008, 02:46 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks