The Artima Developer Community
Sponsored Link

Java Answers Forum
using string buffer or tokenizer

1 reply on 1 page. Most recent reply: Apr 22, 2003 8:54 PM by glkrr

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
jake

Posts: 83
Nickname: onorok
Registered: May, 2002

using string buffer or tokenizer Posted: Apr 21, 2003 9:50 PM
Reply to this message Reply
Advertisement
I have to write a program that reads a sentence in and check to see weather it has a balanced number of parenthesis. how would I do this, I know there is some way to take the spaces out of a sentence and iterate trough each character in a string. How do I use the string buffers and tokenizers?


glkrr

Posts: 4
Nickname: glkrr
Registered: Oct, 2002

Re: using string buffer or tokenizer Posted: Apr 22, 2003 8:54 PM
Reply to this message Reply
U check the jdk1.4 api


u try this code may be u get some idea ...


import java.util.regex.*;

public class ReplaceAll {


public static void main(String args[]){

Pattern p = Pattern.compile("<a href");
StringBuffer buf = new StringBuffer("this is to test hyperlink <a href=http://www.k7mail.com>k7mail.com</a> just see the output and lets see what happens here it is <a href=http://www.k2mail.com> k2mail.com </a>");
Matcher m = p.matcher(buf.toString());
StringBuffer sb = new StringBuffer();
while(m.find()){

m.appendReplacement(sb,"<a target=_blank href");
}
m.appendTail(sb);
System.out.println("The output is "+sb.toString());



}

}

Flat View: This topic has 1 reply on 1 page
Topic: Converting a .java GUI to an .EXE Previous Topic   Next Topic Topic: can't get server to send file to client

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use