473,427 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,427 software developers and data experts.

how do i tokenize a string on the base of special characters such as ' and . ect?

I have used StringTokenizer class to make tokens of a string but my program tokenizes a string only on the basis of spaces but it does not tokenizes on the basis of special characters such as comma(,),full stop(.),single quotes etc.

Consider a sentence or string:
"I don't know who is he."

After compiling it the output of my program is:
I: valid token
don't: valid token
know: valid token
who: valid token
is: valid token
he!:valid token


but my requirement is:
the short form "don't" should be replaced by "do not" and the out should be:

do: valid token
not: valid token

and

he: valid token
!: valid token

I want your help.Can you suggest me what to do?
I'll be thankful to you
Jun 26 '10 #1

✓ answered by rotaryfreak

@Ahsan123pk
take a look at the java api for the StringTokenizer class, there you will find that you can specifically change the default delimiter to whatever you want to with the method
public StringTokenizer(String theString, String delimiters)

http://java.sun.com/j2se/1.4.2/docs/...Tokenizer.html

and if you're still confused on the topic, i encourage you to visit my old professor's website,

http://aimanhanna.com/concordia/comp248/index.htm

there you will find lots of examples on various java topics but the example in particular that will help you is titled "Strings2.java"(.doc)

hope this helps!

2 3565
@Ahsan123pk
take a look at the java api for the StringTokenizer class, there you will find that you can specifically change the default delimiter to whatever you want to with the method
public StringTokenizer(String theString, String delimiters)

http://java.sun.com/j2se/1.4.2/docs/...Tokenizer.html

and if you're still confused on the topic, i encourage you to visit my old professor's website,

http://aimanhanna.com/concordia/comp248/index.htm

there you will find lots of examples on various java topics but the example in particular that will help you is titled "Strings2.java"(.doc)

hope this helps!
Jun 27 '10 #2
Thankyou for the answer it worked.
Jul 11 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Ricardo Jesus | last post by:
I'm reading an XML document and creating a CMS Posting for eacho specific node but i'm trying to save the posting using the title as Posting.Name. For this to work i have to remove all special...
4
by: Ewok | last post by:
let me just say. it's not by choice but im dealing with a .net web app (top down approach with VB and a MySQL database) sigh..... Anyhow, I've just about got all the kinks worked out but I am...
5
by: Sakharam Phapale | last post by:
Hi All, I am using an API function, which takes file path as an input. When file path contains special characters (@,#,$,%,&,^, etc), API function gives an error as "Unable to open input file"....
17
by: Carl Mercier | last post by:
Hi, Is it possible to use special characters like \n or \t in a VB.NET string, just like in C#? My guess is NO, but maybe there's something I don't know. If it's not possible, does anybody...
20
by: bubunia2000 | last post by:
Hi all, I heard that strtok is not thread safe. So I want to write a sample program which will tokenize string without using strtok. Can I get a sample source code for the same. For exp:...
8
by: david.lindsay.green | last post by:
Hello all, I am quite new a web scripting and making web pages in general and I have stumbled across a problem I have as yet been unable to solve. I am trying to take the contents of a textarea box...
5
by: Joe Abou Jaoude | last post by:
Hi, in my code, i need to load a string in an xml document. However this string contains special characters like &,>,<," ... I need to replace these characters by &amp; &lt; ... however this is not...
6
by: TheRealDan | last post by:
Hi all. I'm having a problem with a special characters. I have php script that reads from an xml file and writes to a mysql db. It's a script called phptunest that I found on the net, although the...
3
KevinADC
by: KevinADC | last post by:
Purpose The purpose of this article is to discuss the difference between characters inside a character class and outside a character class and some special characters inside a character class....
5
by: Sobin Thomas | last post by:
Hi All, I want to pass a string that contains many special characters (: \ . _ etc) to another page in my website through query string. In my project I have a Gridview control ,in which there...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.