hello,
I have to read a text and I decided to split it with Scanner class. -
private Vector<String> splitWords(Scanner s) {
-
Vector<String> v = new Vector<String>();
-
while ( s.hasNext() ) {
-
-
String token = s.next();
-
if ( token.length() == 1 && (token == "." || token == ";" || token == "," || token == ":") ) {
-
continue;
-
-
-
}
-
v.add( token );
-
}
-
return v;
-
}
-
and return a vector with all tokens. However as you can see I'd like to don't put in the vector the symbols ; ,.: ? )( etc. I can do as here above (with that ugly if), but I have a text like
"heloworls..... ............... ..."
how can I delete the ............... ............ in agodd way? (the scanner doens't separate the ".............. ............... ..."
thanks
5 1523 Nepomuk 3,112
Recognized Expert Specialist
Well, have a look at regular expressions. They should do the job. Especially make sure to read this.
Greetings,
Nepomuk
string tokenisation my firend, use this class ...!
JosAH 11,448
Recognized Expert MVP @samido
Tokenizers are the old fashioned way of doing things; Scanners or a simple String.split() handle the job much better (by using regular expressions).
kind regards,
Jos
@Nepomuk
Hi, I tri to do this to skip every non-word charachter but it dones't work at all. -
while ( s.hasNext() ) {
-
try {
-
s.skip("\\W");
-
}
-
catch (NoSuchElementException ex) {
-
-
}
-
-
String token = s.next();
-
What's wrong, please?
JosAH 11,448
Recognized Expert MVP
Try this: Scanner.useDeli miter("\\W+");
kind regards,
Jos
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Blue Ocean |
last post by:
In short, it's not working right for me.
In long:
The program is designed to read numbers from an accumulator and speak
them out loud. Unfortunately, the class that contains the method to
read off large numbers is only for integers. My intention is to split
a String across the Regex of ".". However, this code does not work:
private void doRealValueOf(String text) {
|
by: Brian Glen Palicia |
last post by:
My goal is to accept input from the user into a text box and then
parse the data using split(). The first step is this tiny program to
test the split() function. It runs in IE, but in Mozilla it just
hangs and keeps loading forever. I checked around on the web and in
USENET, but I haven't seen any mention of split() not working in
Mozilla. Thoughts? Thanks in advance.
<HTML>
<HEAD>
</HEAD>
|
by: William Stacey [MVP] |
last post by:
Would like help with a (I think) a common regex split example. Thanks for
your example in advance. Cheers!
Source Data Example:
one "two three" four
Optional, but would also like to ignore pairs of brackets like:
"one" <tab> "two three" ( four "five six" )
Want fields like:
|
by: Cor |
last post by:
Hi Newsgroup,
I have given an answer in this newsgroup about a "Replace".
There came an answer on that I did not understand, so I have done some
tests.
I got the idea that someone said, that the split method and the
regex.replace method was better than the string.replace method and replace
function. I did not believe that.
|
by: Ben |
last post by:
Hi
I am creating a dynamic function to return a two dimensional array from a
delimeted string.
The delimited string is like:
field1...field2...field3...
field1...field2...field3...
field1...field2...field3...
| |
by: Sen Haerens |
last post by:
I'm using string.split(/^$/m, 2) on a curl output to separate header
and body. There’s an empty line between them. ^$ doesn’t seem to work...
Example curl output:
HTTP/1.1 404 Not Found
Date: Wed, 22 Feb 2006 00:01:45 GMT
Server: Apache/1.3.33 (Darwin) PHP/5.1.2 mod_perl/1.29
Transfer-Encoding: chunked
Content-Type: text/html; charset=iso-8859-1
|
by: Saurabh |
last post by:
Hi everyone,
I am looking for some expert advise to get me out of trouble. I am looking for a solution in C# which will allow me to split the below string in the format provided. The String.Split() allows only a single char as a delimiter.So I cannot use that as well.
Original String
"*** MASTER (Supervisor) *** September 23, 1997 at 3:22pm \r\nThis is the first line of text. There will be many more beneath this on so look...
|
by: garyusenet |
last post by:
I'm working on a data file and can't find any common delimmiters in the
file to indicate the end of one row of data and the start of the next.
Rows are not on individual lines but run accross multiple lines.
It would appear though that every distinct set of data starts with a
'code' that is always the 25 characters long. The text is variable
however.
Assuming i've read the contents of the file into the string myfile, how
do i split my...
|
by: AMP |
last post by:
Hello,
I am trying to split a string at the newline and this doesnt work:
String Channel = FileName.Split("\r");
What am I doing wrong?
Thanks
Mike
|
by: Robert Dodier |
last post by:
Hello,
I'd like to split a string by commas, but only at the "top level" so
to speak. An element can be a comma-less substring, or a
quoted string, or a substring which looks like a function call.
If some element contains commas, I don't want to split it.
Examples:
'foo, bar, baz' ='foo' 'bar' 'baz'
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |