aspose file tools*
The moose likes Beginning Java and the fly likes Split and other String functions/methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Split and other String functions/methods" Watch "Split and other String functions/methods" New topic
Author

Split and other String functions/methods

Miguel Enriquez
Ranch Hand

Joined: Mar 13, 2004
Posts: 94
i have these code but not work in myproc2 any advices why?

NOTE: i am Delphi programmer and i need know the next other string functions:
wcade="Mycade|XXX"
1) Pos("|",wcade) return me: 7 if not exist return me a 0
2) Delete(wcade,1,2) return me: cade|XXX
in java?
[ edited to format code and to preserve formatting using the [code] and [/code] UBB tags -ds ]
[ March 15, 2004: Message edited by: Dirk Schreckmann ]
Carlos Failde
Ranch Hand

Joined: Oct 20, 2000
Posts: 84
I think the myproc2() problem is the regex expression.
mycade.split("\\|")
will split around the | character as I guess you are trying to do.
1) Pos("|",wcade) return me: 7 if not exist return me a 0

wcade.indexOf('|');
2) Delete(wcade,1,2) return me: cade|XXX

You could put something together with substring() I guess

Note that indexing begins from 0 so I had to adjust your numbers
would return Mcade|XXX
Use the api docs for more information on String methods.
Miguel Enriquez
Ranch Hand

Joined: Mar 13, 2004
Posts: 94
thanks worked.....
much thanks
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Welcome to JavaRanch, Miguel!
I've very happy that a fellow rancher has already helped to point you in the right direction for solving your problem. I'm posting just to suggest a simple tip to help improve communications in these forums.
When posting code, please be sure to surround the code with the [code] and [/code] UBB Tags. This will help to preserve the formatting of the code, thus making it easier to read and understand.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Edwin Keeton
Ranch Hand

Joined: Jul 10, 2002
Posts: 214

The parameter to split() is a regular expression. '|' is a regex logical operator. Change "|" to another expression, (like maybe ":") and you will get an array of strings as follows:
Chihuahua
30
Jose Alfredo Miguel
1


SCJP, SCWCD
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Split and other String functions/methods