How check if a string contains a generic character?
I want know how i can check if this string
String mio= new String("Error 101");contains this substring
1xxwhere "xx" are two generic characters that follow "1".
Thanks
Message was edited by:
PremierITA
Use a regular expression.Pattern threeDigitNumberThatStartsWith1 = Pattern.compile(".*1\\d\\d.*");
Matcher matcher = pattern.matcher(mio);
if(matcher.matches()) {
// found it!
else {
// didn't find it
}More about pattern matching here: http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html
Similar Messages
-
Check if a string contains another string
can anybody help?
String st="DC";
how can i check if another string contains "DC" or not?How bout
if(someString.indexOf(st) != -1) {
//someString contains st at some point
} -
Find Whether String Contain Sequence Of Character Or Not
<b>
hello friend,
I am to the new java. I need to findout whether the string contain sequence of character or not. I tried like this
personLastName.length()> 0
It will return true even my string contains space. Is there any other method in java to find out ?
ThanksThere are a few ways to do that. Check out the String class or Regex for one that suits but
myString.indexOf(whatIWantToFindString)is an old favorite. It returns -1 if the sequence is not there, or the starting index if it is. The javadocs are your friends.
regards -
How to parse a string containing xml data
Hi,
Is it possible to parse a string containing xml data into a array list?
my string contains xml data as <blood_group>
<choice id ='1' value='A +ve'/>
<choice id ='2' value='B +ve'/>
<choice id ='3' value='O +ve'/>
</blood_group>how can i get "value" into array list?There are lot of Java XML parsing API's available, e.g. JAXP, DOM4J, JXPath, etc.
Of course you can also write it yourself. Look which methods the String API offers you, e.g. substring and *indexOf. -
Unique regular expression to check if a string contains letters and numbers
Hi all,
How can I verify if a string contains numbers AND letters using a regular expression only?
I can do that with using 3 different expressions ([0-9],[a-z],[A-Z]) but is there a unique regular expression to do that?
Thanks allDarin.K wrote:
Missed the requirements:
single regex:
^([[:alpha:]]+[[:digit:]]+|[[:digit:]]+[[:alpha:]])[[:alnum:]]*$
You either have 1 or more digits followed by 1 or more letters or 1 or more letters followed by 1 or more digits. Once that is out of the way, the rest of the string must be all alphanumerics. The ^ and $ make sure the whole string is included in the match.
(I have not tested this at all, just typed it up hopefully I got all the brackets in the right place).
I think you just made my point. TWICE. While the lex class would be much more readable as a ring.... I know all my brackets are in the correct places and don't need to hope.
Jeff -
How to determine if string contains HashSet item using LINQ
Hi,
I know how to iterate through a HashSet to see if an item is contained in a string. But, I can't quite figure out how to do it with LINQ.
Something like if( string.Contains(???))
I would appreciate any help!
Thanks much!!Thanks everyone. I like the examples posted above.
Actually, what I want to know is if any HashSet values can be found in a string using LINQ
HashSet<string> terminals = new HashSet<string>();
terminals.Add("FD4A");
terminals.Add("FD4B");
terminals.Add("FD4C");
//a collection of a bunch of transactions done at various terminals
List<string> transactionList = new List<string>();
foreach (string transaction in transactionList)
foreach (string terminal in terminals)
if (transaction.Contains(terminal) == true)
//this is one of the transactions I want - do something
break;
Thanks much and have a great weekend!! -
How to Identify whether string contains only numbers
Hi Experts,
How to identify whether a string contains only numbers...
Thanks & Regards,
Neeraj.Hi Neeraj,
ISNUMERIC(String_Field)
The above function returns '0' for non-numerics and
'1' for numeric
Hope this helps.
Regards,
Bala -
How to insert a string containing a single quote to the msql database? help
how can i insert a string which contains a single quote in to database... anyone help
Message was edited by:
sijo_jamesAbsolutely, Positively use a PreparedStatement. Do not use sqlEscape() function unless you have some overriding need (and I don't know what that could possibly be).
There are 1000's of posts on the positive aspects of using a PreparedStatement rather than using a Statement. The two primary positive attributes of using a PreparedStatement are automatic escaping of Strings and a stronger security model for your application. -
How to encode a string containing HTML
I have a string which contains HTML tags. This will be written to file so i need to encode it i guess to ISO-8859-1
Please note: i am using JDK1.2.2
My code is
bytes = new byte[(int)rs.getString(k).length()*4];
desc = new String(bytes, "ISO-8859-1");
This does not work. The tags remain the same i.e. "<" and ">" are still there in the String. In what format should HTML be encoded and what am i doing wrong above?or...
* Encodes any special characters in the specified string with their
* entity equivalents.
* @param str the original string
* @return the encoded string
public static String encodeEntities(String str) {
StringBuffer sb = new StringBuffer(str);
// must replace '&' first
char[] chars = { // list of characters to replace
'&', '<', '>', '\'', '\"'
String[] ents = { // list of entities to replace with
"&", "<", ">", "'", """
int len = Math.min(chars.length, ents.length);
for(int i = 0; i < len; i++) {
for(int j = 0; j < sb.length(); j++) {
if(sb.charAt(j) == chars) {
sb.replace(j, j+1, ents[i]);
return sb.toString();
* Decodes any entities in the specified string with their character
* equivalents.
* @param str the encoded string
* @return the decoded string
public static String decodeEntities(String str) {
if(str == null) {
return null;
StringBuffer sb = new StringBuffer(str);
String[] ents = { // list of entities to replace
"&", "<", ">", "'", """
String[] chars = { // list of characters to replace with
"&", "<", ">", "\'", "\""
int len = Math.min(chars.length, ents.length);
int k = 0;
for(int i = 0; i < len; i++) {
for(int j = 0; j < sb.length(); j++) {
k = j + ents[i].length();
if(k >= sb.length()) {
break;
if(sb.substring(j, k).equals(ents[i])) {
sb.replace(j, k, chars[i]);
return sb.toString(); -
How to converts this string to a new character array???
I have string that get from g.getDirectory();
that string is "D:\Songs\Judas Priest"
and I want to convert to charArray[][] = {{"D",":","\","S","o","n",.....}};
how can I do it??
:'(I have ploblem again :'(
indeed I want to change string
D:\Songs\Judas Priest
to
D:/Songs/Judas Priest
I do this for upload my picture to program by directory
but when I use getDirectory();
It only save "D:\Songs\Judas Priest"
so I must change "\" to "/"
I think I must use "for" and check if it found "\" it will be change to "/"
but I don't know how to write?
public String[][] sliceNwrap(String str){
dir[0] = new String[str.length()];
for(int ndx=0;ndx<str.length();ndx++){
if(str.substring(ndx, ndx+1)=="\\"){
dir[0][ndx]= "/";
else{
dir[0][ndx] = str.substring(ndx, ndx+1);
return dir;
It still "D:\Songs\Judas Priest" :'( help me plz -
How to split a string which contents 2byte character
hi all,
i wanna split a string into substrings five bits a time
the problem is the original string may contents 2byte characters
and if the split bit is a 2byte character we only take the first four bits.
the 2byte character is used for the next five bits.
so could you tell how carry is out.
thanks in advancehi all,
i wanna split a string into substrings five bits a time
the problem is the original string may contents 2byte characters
and if the split bit is a 2byte character we only take the first four bits.
the 2byte character is used for the next five bits.
so could you tell how carry is out.
thanks in advance -
Quick string question finding if a string contains a character
hello peeps
is there a quick way of checking if a string contains a specific character
e.g.
myString="test:test";
myString.contains(":");
would be true
any ideas on a quick way of doing itis there a contains() method in 1.4.2? i couldnt see
it in the docsNo there isn't. But the 1.5 has a contains(CharSequence s) method. -
How to find out whether the String contains chinese characters
I need to check if the string contains chinese characters in Java. Does anyone know how to do it? thx.
Since Java strings contain UNICODE code points, check the content against the relevant page here - http://www.unicode.org/charts/ .
-
How to do string contains in drools.
hi everyone
i'm using drools for a project and have come to a problem. in two of my rules i need to check if a string contains some characters but can't seem to do get the rules to be excepted. if anyone could help me i would be very grateful.
thanks in advance
mikeDisplay the rules.
-
Hi there,
If given string contains a special character in the first position..i need to delete the character from the string.
please suggest a way..It's clunky, but try this:
To replace special character with space.
data: w_val type string.
move old_string+0(1) to w_val.
replace first occurance of w_val in old_string with space.
OR
To remove it entirely
shift old_string by 1 places left. " Shifts string to left and drops off characters to left.
Steve
Maybe you are looking for
-
ADF : How to pass a variable from one frame to another frame ?
Hi, I have an html page divided into 3 frames, all inside a frameset. Each frame are linked to a specific .jsf page (src attribute). When I list a list thanks to a ADF datatable in ONE frame, each row has a "show more" button. When I click this butto
-
Function Module GUI_DOWNLOAD in SAP 4.6c
Hi All, I have uploaded a JPG file to a database table and when using the below function modules in the SAP 4.7 server its not opening the file. The Below code is written for the double click event. The same code works for the ECC 6.0 version please
-
Sol Man 4.0 installation - dispatcher stops
Hi All, I have just installed oracle 10.2.0.2. Now I am installing Solution Manager 4.0. (OS is windows 2003) I have reached the stage where it tries to 'start the ABAP instance'. The issues is that the dispatcher stops and the sapinst throws error.
-
How to Recursively traverse a Dom Tree
Hi there, I'm new to java and xml and would like to see some sample code on recursively traversing a DOM tree in java, printing out all Element, Text, etc to the console window. Please help
-
I have a 2012 macBook Pro 13" and the option "Use audio port for" does not appear at all in the sound menu. why is this? im running mountain Lion 10.8.2