• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to match the exact string value in the list of comma separated string  RSS feed

 
kerthi Joe
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have List of array String,

Info = [cat, dog, frogs, monkey];

Another list of array String,

Compare_val = ['I,have,a,pretty,dogs, and many,cat' , 'My,dog,is,cute', 'My, garden, has, many_frogs'];

I have to compare both these string and have to come out with the output,

My Compare_val [0] has 'cat' as matching string.
My Compare_val [1] has 'Dog' as matching string
My Compare_val [2] has 'frogs' as matching string

Is there any regex pattern to acheive this?

I tired with the contains, But if I use Info.contains(, + Compare_val);

my first answer,
My Compare_val [0] is 'dog', but it should be 'cat'

My third answer, does not match at all. since I check the value only after comma (,)

Seeking your help,
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So if I understand your question correctly, you want to compare the first element in List 1 with the first element in List 2 and so on? Is that correct?
 
Ahmed Bin S
Ranch Hand
Posts: 385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) post your current code
2) look at String.split()
3) you have a pretty dog and many cats, and not a pretty dogs and many cat
 
kerthi Joe
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Joe Harry yes, I have to check whether the Info array values are in Compare_val. I have to iterate the Compare_val over the Info array and find what values are matching.

Ahmed Bin S : 3) you have a pretty dog and many cats, and not a pretty dogs and many cat - the third statement must have pretty 'dogs' and many cat and thats why it should match with 'cat' not with the 'dog' because of 'dogs'
 
Ahmed Bin S
Ranch Hand
Posts: 385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kerthi Joe wrote:
Joe Harry yes, I have to check whether the Info array values are in Compare_val. I have to iterate the Compare_val over the Info array and find what values are matching.

Ahmed Bin S : 3) you have a pretty dog and many cats, and not a pretty dogs and many cat - the third statement must have pretty 'dogs' and many cat and thats why it should match with 'cat' not with the 'dog' because of 'dogs'


As I said above, please post your code - if you describe to me what you're doing and if you post the code, I know which one I am more likely to read and respond to.

And you still don't understand what I am saying, you are mixing singular with plural, which is GRAMMATICALLY incorrect.
a = singular
dogs =plural
Therefore, you cannot use a with dogs - it is wrong. So you should say "I have a pretty dog" or "I have many pretty dogs".
Similarly,
many = plural
cat = singular
Therefore, you cannot use many with cat - it is wrong. So you should say "many cats" or "a cat".
Therefore, your sentence should either be:
"I have a pretty dog and many cats"
or
"I have many pretty dogs and a cat".

 
Campbell Ritchie
Marshal
Posts: 56534
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please explain carefully what you are trying to do, rather than how you think you can do it. Maybe you can explain it to me, but there is somebody harder to convince whom you should explain it to as well: yourself. When you know the reason for your programming, it will be easier to work out the mechanics.
 
kerthi Joe
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here goes my code,


Hope am clear.
 
Stephan van Hulst
Saloon Keeper
Posts: 7973
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kerthi, this is not valid Java code. Please PostRealCode.
 
kerthi Joe
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is the exact list am using in my code. This is one of the logic in my program! Please tell me which line of code you did not did not understand . I will explain
 
Dave Tolls
Ranch Foreman
Posts: 3056
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you post code you should post only the code in code tags.
It's all the other non-code stuff (like the list data) that is confusing people as to what exactly is your relevant code.
It confused me.

Anyway, to take a couple of your expected results, ECC and SO8 will not be found.
Your code is searching for:

so if there's no leading comma it won't be found.

In addition, that is SO8 (an O not a zero) and your search list has S08 (a zero not an O).
 
kerthi Joe
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya thanks Dave,

Sorry, It is my typo mistake search list also has 'S08'

If there is no leading comma, it will not get the right result. I need a solution to find those values also.

That's my question.





 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!