• Post Reply Bookmark Topic Watch Topic
  • New Topic

String Algorithm  RSS feed

 
ali zaid
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

How to write string algorithm to determine where or not the string match this pattern
String s={([]),([]),([]),([])}


Thanks in Advance
 
ali zaid
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ali zaid wrote:Hi

How to write string algorithm to determine where or not the string match this pattern
String s={([]),([]),([]),([])}


Thanks in Advance


String s="{([]),([]),([])(,[])}";
without using pattern matcher
 
Liutauras Vilda
Marshal
Posts: 4651
319
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. String is equal (method from String class) to yours specified?
2. String length is same as your specified pattern and contains (method from String class) it?
3. Starts with (method from String class) your pattern and contains space afterwards.
4. Ends with (method from String class) your pattern and has space in front of it.
5. Find first occurrence of space character, then find consequent space character, and check if such substring between spaces is equal to your pattern.
6. Find first occurrence of space character, then check if further substring contains your pattern, and then ensure it is the end of string.

I guess what I'm trying to say is, what are the requirements? One sentence isn't enough as explanation.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ali zaid wrote:Hi

How to write string algorithm to determine where or not the string match this pattern
String s={([]),([]),([]),([])}

That is not a pattern, that is an example.  If i said "how do I write a method that finds numbers like 2?"  you'd ask "do you mean even? prime? single digits?  integers?"

There are many, many ways to interpret a single example.  you need to tell us exactly what you mean.
 
ali zaid
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Liutauras Vilda wrote:1. String is equal to yours specified?
2. String length is same as your specified pattern and contains (method from String class) it?
4. Starts with your pattern and contains space afterwards.
5. Ends with your pattern and has space in front of it.
3. Find first occurrence of space character, then find consequent space character, and check if such substring between spaces is equal to your pattern.
4. Find first occurrence of space character, then check if further substring contains your pattern, and then ensure it is the end of string.

I guess what I'm trying to say is, what are the requirements? One sentence isn't enough as explanation.


for example




m1("([1]");///this should print missed   )
m1("([1)");///this should print missed ]

m1("([2]) ([3])) . //this should print missed ,







 
Liutauras Vilda
Marshal
Posts: 4651
319
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again. Not clear at all.

What is that bit {([]),([]),([]),([])} ? String which you are looking or something else?

Looking to your latest post, all became even more unclear.

 
Liutauras Vilda
Marshal
Posts: 4651
319
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would be clearer if you'd say:
1. Every sequence needs to be enclosed in {}.
2. Every numeric value needs to be enclosed in [], which itself enclosed in ().
3. If there are more than one numeric value in such sequence, after the () supposed to be a comma and other numeric value needs to satisfy rule number 2.

This is something what we'd expect to hear from you.
For such task you'd need to write your own parser which might be quite complicated as I've listed only 3 rules, but there would be most likely more. You should know them before you start any coding.
 
Liutauras Vilda
Marshal
Posts: 4651
319
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ali zaid wrote:m1("([1]");///this should print missed   )


What this should print?

How about this?

This?




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