-3

I am trying to get a string between two strings but contains & indexOf method not working.

Please help me out if someone had the same issue.

Main String = [)>061PKDU 127 161/3R4C22PDUW 30 016D20110714STU8X195955

I am trying to find string 16D but contains method giving me false & indexOf always returning -1

Please let me know if am doing anything wrong otherwise your help would be appreciated. Thanks!

Please have a look at the screenshot for more info,

enter image description here

Dharmbir Singh
  • 17,485
  • 5
  • 50
  • 66
  • 2
    [I bet on not visible char](https://ideone.com/XoMDWO) – Selvin Apr 04 '19 at 10:45
  • https://stackoverflow.com/a/90780/10470378 – ronginat Apr 04 '19 at 10:46
  • @Selvin Please have a look on my screenshot what i am doing wrong? I am doing same but its not going in if condition neighter its giving proper index. – Dharmbir Singh Apr 04 '19 at 10:48
  • 2
    Perhaps you would like to post a [mcve] instead of a screenshot. – khelwood Apr 04 '19 at 10:48
  • @khelwood I have provided everything... even main string & string as well which i want. – Dharmbir Singh Apr 04 '19 at 10:52
  • @DharmbirSingh I see `data = data.toLowerCase();` which may explain that issue even if it is commented out in your screenshot you might forgeted to undo that lowercase stuff elsewhere? – Eritrean Apr 04 '19 at 11:06
  • @Eritrean I just tried with lower case as well but its not working, thats why i commented it. – Dharmbir Singh Apr 04 '19 at 11:08
  • @DharmbirSingh I copy pasted your string and both `contains` and `indexOf` are working fine for me. You may want to `Clean Project` to delete all intermediate/cached build files or `Rebuild Project`. – Eritrean Apr 04 '19 at 11:15
  • @Eritrean Let me try your suggestion, FYI i tried same code in another class its working fine but i don't know why its not working in current class. – Dharmbir Singh Apr 04 '19 at 11:17

1 Answers1

0

Finally i got solution,

Main String = [)>061PKDU 127 161/3R4C22PDUW 30 016D20110714STU8X195955

This string showing me length 64 even character is 57, It's containing with \u00D character which is not visible.

So the original string is [)>061\u00DPKDU 127 161/3R4C22\u00DPDUW 30 01\u00D6D20110714\u00DSTU8X195955

So i have replaced \u00D with "" now its working perfect.

Thanks guys for your help.

Dharmbir Singh
  • 17,485
  • 5
  • 50
  • 66