Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a string between two characters?

Tags:

java

string

I have a string,

String s = "test string (67)"; 

I want to get the no 67 which is the string between ( and ).

Can anyone please tell me how to do this?

like image 780
Roshanck Avatar asked Sep 26 '12 05:09

Roshanck


People also ask

How do I extract a string between two characters in Python?

A Quick Guide to Using split() This function can be used to split strings between characters. The split() function takes two parameters. The first is called the separator and it determines which character is used to split the string. The split() function returns a list of substrings from the original string.


1 Answers

There's probably a really neat RegExp, but I'm noob in that area, so instead...

String s = "test string (67)";  s = s.substring(s.indexOf("(") + 1); s = s.substring(0, s.indexOf(")"));  System.out.println(s); 
like image 190
MadProgrammer Avatar answered Sep 21 '22 22:09

MadProgrammer