-2

I need to develop a code to check the String has got any Semicolon. And charector can be in any flavor.

            Charector                   : ;
            Ascii                        : 59
            HTML Entity (decimal)        : &#59
            HTML Entity (hex)            : &#x3b
            Alt                          : 059
            Alt                          : 59
            UTF-8 (hex)                  : 0x3B (3b)
            UTF-8 (binary)               : 00111011
            UTF-16 (hex)                 : 0x003B (003b)
            UTF-16 (decimal)             : 59
            UTF-32 (hex)                 : 0x0000003B (3b)
            UTF-32 (decimal)             : 59

    etc...
Is there a proper way with regular expression , where I can check all flavors of semicolon.
Kumar
  • 1,106
  • 4
  • 15
  • 33

3 Answers3

1

Strings don't have an encoding. So you need to just check on myString.contains(";")

Ivo
  • 18,659
  • 2
  • 23
  • 35
  • Comparing only ";" is I know, but I want a comparison to check all flavors of Semicolon(May be my english is wrong). What I mean a String can be "xyz;" or "0x0000003B" , my comparison should return true saying Semi colon is there in the String. So I thought to use the Regular expression. – Kumar Jul 09 '14 at 13:40
  • If the string is "0x0000003B" it is not a semicolon but actually that string. encoding only happens at bytelevel, there should be no need to try to match the string on any of those encodings – Ivo Jul 09 '14 at 13:42
  • What you mean is Value in String "0x0000003B" is a String representation not Hexadecimal. What happen if I send this to SQL query after "Order By" – Kumar Jul 09 '14 at 13:46
0

What about

if(yourString.contains(";")){
    // Do things
}

Why do you need a regex just to see if it contains one character ?

singe3
  • 2,065
  • 4
  • 30
  • 48
  • Comparing only ";" is I know, but I want a comparison to check all flavors of Semicolon(May be my english is wrong). What I mean a String can be "xyz;" or "0x0000003B" , my comparison should return true saying Semi colon is there in the String. So I thought to use the Regular expression. – Kumar Jul 09 '14 at 13:40
0

If you need to check for semicolon, all you need to do is:

int pos = yourString.indexOf(";");
if (pos != -1) {
  //...semicolon found at position pos
}

What do you actually mean by "flavours of semicolon"?

tomorrow
  • 1,260
  • 1
  • 14
  • 26
  • Comparing only ";" is I know, but I want a comparison to check all flavors of Semicolon(May be my english is wrong). What I mean a String can be "xyz;" or "0x0000003B" , my comparison should return true saying Semi colon is there in the String. So I thought to use the Regular expression. – Kumar Jul 09 '14 at 13:39
  • Well, but what would then be an expected result for "0x0000003B;"? Is that one semicolon or two? – tomorrow Jul 09 '14 at 13:51