likecoding Posted October 28, 2018 Share Posted October 28, 2018 (edited) Hello, String = "select * from employees where ID = &myID&" How to return the text between two &s. Thanks. Edited October 28, 2018 by likecoding Link to comment Share on other sites More sharing options...
justsomeguy Posted October 29, 2018 Share Posted October 29, 2018 It would be best to use a regular expression. You could also get the positions of the various delimiter characters and then get the text between the first and second, then the third and fourth if there are more, etc. Link to comment Share on other sites More sharing options...
Makwana Prahlad Posted September 2, 2020 Share Posted September 2, 2020 Hello,@likecoding Please try this code,To How to return string between special characters public static String innerSubString(String txt, char prefix, char suffix) { if(txt != null && txt.length() > 1) { int start = 0, end = 0; char token; for(int i = 0; i < txt.length(); i++) { token = txt.charAt(i); if(token == prefix) start = i; else if(token == suffix) end = i; } if(start + 1 < end) return txt.substring(start+1, end); } return null; } I hope this code will be useful for you. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now