| | |
How could i find string that it's the end with "," and "." ?
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jul 2009
Posts: 21
Reputation:
Solved Threads: 0
import java.util.*;
class FindString
{
public static void main(String arg[])
{
Scanner ob=new Scanner(System.in);
String st="I am a student, you're also a .";
String search;
String st2="";
String st3="";
int i,c=0;
System.out.println(st);
System.out.println("Enter your word to search: ");
search=ob.next();
do
{
i=st.indexOf(search);
if(i!=-1)
{
st2=st.substring(0,i);
st2+=st3;
st2+=st.substring(i+search.length());
c=c+1;
st=st2;
}
}while(i!=-1);
System.out.println("Found=" + c);
}
}
Sorry for all friends, that i could use the bb tag code. Wish you all feel me .
class FindString
{
public static void main(String arg[])
{
Scanner ob=new Scanner(System.in);
String st="I am a student, you're also a .";
String search;
String st2="";
String st3="";
int i,c=0;
System.out.println(st);
System.out.println("Enter your word to search: ");
search=ob.next();
do
{
i=st.indexOf(search);
if(i!=-1)
{
st2=st.substring(0,i);
st2+=st3;
st2+=st.substring(i+search.length());
c=c+1;
st=st2;
}
}while(i!=-1);
System.out.println("Found=" + c);
}
}
Sorry for all friends, that i could use the bb tag code. Wish you all feel me .
•
•
Join Date: Jan 2008
Posts: 3,844
Reputation:
Solved Threads: 503
•
•
•
•
import java.util.*;
class FindString
{
public static void main(String arg[])
{
Scanner ob=new Scanner(System.in);
String st="I am a student, you're also a .";
String search;
String st2="";
String st3="";
int i,c=0;
System.out.println(st);
System.out.println("Enter your word to search: ");
search=ob.next();
do
{
i=st.indexOf(search);
if(i!=-1)
{
st2=st.substring(0,i);
st2+=st3;
st2+=st.substring(i+search.length());
c=c+1;
st=st2;
}
}while(i!=-1);
System.out.println("Found=" + c);
}
}
Sorry for all friends, that i could use the bb tag code. Wish you all feel me .
[code=JAVA]
// paste code here
[/code]
Non-Java-specific BB Code.
[code]
// paste code here
[/code]
JAVA Syntax (Toggle Plain Text)
class FindString { public static void main(String arg[]) { Scanner ob=new Scanner(System.in); String st="I am a student, you're also a ."; String search; String st2=""; String st3=""; int i,c=0; System.out.println(st); System.out.println("Enter your word to search: "); search=ob.next(); do { i=st.indexOf(search); if(i!=-1) { st2=st.substring(0,i); st2+=st3; st2+=st.substring(i+search.length()); c=c+1; st=st2; } }while(i!=-1); System.out.println("Found=" + c); } }
I don't understand what you're trying to do.
•
•
Join Date: May 2008
Posts: 41
Reputation:
Solved Threads: 7
Please explain your problem properly. Cant get it what you want.
From what I have understood... to find whether a string that ends with "," or ".",
eg.
From what I have understood... to find whether a string that ends with "," or ".",
eg.
java Syntax (Toggle Plain Text)
String str = "Hello World."; if(str.charAt(str.length-1)==',' || str.charAt(str.length-1)=='.') { // Your Code }
Last edited by harsh2327; Jul 25th, 2009 at 2:00 pm.
<(^.^)>.....HM.....<(^.^)>
•
•
•
•
Please explain your problem properly. Cant get it what you want.
From what I have understood... to find whether a string that ends with "," or ".",
eg.
java Syntax (Toggle Plain Text)
String str = "Hello World."; if(str.charAt(str.length-1)==',' || str.charAt(str.length-1)=='.') { // Your Code }
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
![]() |
Similar Threads
- search for string in text file then find a different string after (C++)
- find string in txt file (C++)
- Cast from string "" to type 'Integer' is not valid. (ASP.NET)
- Something about String.split("-"); problem (Java)
- Pls Help vb $ excell “Couldn't find installable ISAM� error. (Community Introductions)
- google "keyword" question (Search Engine Optimization)
- "String Index Out of Range" ACK!! (Java)
- "Cannot find server or DNS Error" (Web Browsers)
- My "if" is not good (C)
Other Threads in the Java Forum
- Previous Thread: Help with LR parser algorithm
- Next Thread: Solution to the multithreaded program needed
Views: 383 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for Java
911 addball addressbook android api append apple applet application arguments array arrays automation binary bluetooth button chat class classes client code component css csv database draw eclipse ee error event exception file fractal game givemetehcodez graphics gui helpwithhomework html ide image input integer j2me java javaarraylist javaprojects jmf jni jpanel julia jvm key linux list loan loop map method methods mobile netbeans newbie number object oracle output packets phone print problem program programming project recursion reporting robot scanner screen se server service set size sms socket software sort sql stream string swing test threads time transfer tree ubuntu windows wrong






