Switch to full style
Java2 codes,problems ,discussions and solutions are here
Post a reply

help me regarding StringBuffer.indexOf(String)

Tue Jul 31, 2007 3:16 pm

help me regarding StringBuffer.indexOf(String),i have tried both jdk1.4 and jdk1.6 for the following code to work..can any1 suggest me solution

Code:
psvm(String SubmitDate)
{
StringBuffer returnQuery  = new StringBuffer();
String dateString="";
returnQuery.append("SELECT * FROM ");
    returnQuery.append(view);
    returnQuery.append(userString);
    returnQuery.append(envString);
    returnQuery.append(requestidString);
    returnQuery.append(statusString);

    if((Submitdate==null) || (Submitdate.equals("")))
    {
        dateString="";
    }
    else if(returnQuery.indexOf("where")>0)
        dateString="  AND SUBMIT_DATE LIKE '"+Submitdate+"%'";
    else 
        dateString
=" WHERE SUBMIT_DATE LIKE '"+Submitdate+"%'";

}
 
iam getting error as the method indexOf(String) is undefined for type StringBuffer

Can any1 suggest me...



Re: help me regarding StringBuffer.indexOf(String)

Tue Jul 31, 2007 4:42 pm

There is no function called indexOf in the class StringBuffer

I suggest you use String instead of StringBuffer .And when you append you use the operator '+' .For example :
Code:
String name="Tom";
name+="AAA";
name+="aaa";


now the content of name is "TomAAAaaa"

Re: help me regarding StringBuffer.indexOf(String)

Thu Aug 02, 2007 8:08 am

I tried this code...
Code:
public static void main(String[] args) {
StringBuffer mybuff=new StringBuffer("Mohamed Sami");
mybuff.append(" ddd");
System.out.print(mybuff.indexOf("ddd"));


}


and the output is 13.... :grin:

Post a reply
  Related Posts  to : help me regarding StringBuffer.indexOf(String)
 difference between the String and StringBuffer     -  
 Read file content to StringBuffer String object     -  
 recursive string reversal- reverse string     -  
 Splitting a String Based on a Found String     -  
 check if string ends with specific sub-string in php     -  
 check if string start with a specific sub-string in PHP     -  
 String token for string split     -  
 Pad a string to a certain length with another string     -  
 String to sql.Date     -  
 find a string     -  

Topic Tags

Java Strings