Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Library : Other (not classified elsewhere) » How to split a sentence into words
How to split a sentence into words [message #29773] Tue, 16 November 2010 08:22 Go to next message
o_wild is currently offline  o_wild
Messages: 28
Registered: December 2008
Location: Urmqi
Promising Member

Hi, everybody. I can find built-in split functions in other languages or platforms, see below.
// a java program that split a sentence into words
import java.util.Scanner;

public class StringBufferedTest {
 public static void main(String[] args) {
  Scanner sc=new Scanner(System.in);
  System.out.print("Please Input a sentence: ");
  String sent=sc.nextLine();  
  String str[]=sent.split(" ");  
  for(int i=0;i<str.length;i++){
   System.out.println(str[i]);
  }
 }
}
But in U++, i haven't found the same function yet. How can i implement this function?

[Updated on: Tue, 16 November 2010 08:58] by Moderator

Report message to a moderator

Re: How to split a sentence into words [message #29774 is a reply to message #29773] Tue, 16 November 2010 09:15 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3003
Registered: August 2008
Ultimate Member
Hello o_wild

It could be done this way:

Vector <String> res = Split("Hello how are you", ' ');

Sorry: Split functions are not documented yet.


Best regards
IƱaki
Re: How to split a sentence into words [message #29786 is a reply to message #29774] Wed, 17 November 2010 09:07 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12049
Registered: November 2005
Ultimate Member
Note there is a 'ignoreempty' parameter (default = true) - if you set it to false, 'empty' texts are not ignored.

In other words (note that there are TWO spaces between words):

Split("Hello  world", ' ') == 2
Split("Hello  world", ' ', false) == 3

Re: How to split a sentence into words [message #29788 is a reply to message #29786] Wed, 17 November 2010 10:45 Go to previous message
o_wild is currently offline  o_wild
Messages: 28
Registered: December 2008
Location: Urmqi
Promising Member

Thanks. Upp is really cool!
Previous Topic: Error in OLE?
Next Topic: [bug report]problem about processing WM_PAINT message
Goto Forum:
  


Current Time: Wed Oct 16 04:11:23 CEST 2019

Total time taken to generate the page: 0.01102 seconds