• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
RE: subStrings separated by...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: subStrings separated by...


  • Subject: RE: subStrings separated by...
  • From: "Adam Ramadan" <email@hidden>
  • Date: Wed, 17 Dec 2003 16:58:04 -0500

This is a generic Java question, not specific to WebObjects, but there are
two ways you can do this in Java:

1. java.util.StringTokenizer - this is similar to what you are doing in
Obj-C, although it doesn't return an array. This has been in Java 1.0.

StringTokenizer tokens = new StringTokenizer(stringVar, "-");
while (tokens.hasMoreTokens()) {
	String token = tokens.nextToken();
	...
}

2. In Java 1.4 there is a split method:

String[] tokens = stringVar.split("-");

However, what you're trying to do is validate a pattern of characters, so if
you write a regular expression describing the pattern, you can just call:

boolean correct = stringVar.matches(regex);

3. Maybe there is some support in the WebObjects libraries to get an NSArray
of Strings. I'm new to WebObjects, so I really have no idea, but maybe
someone else does?

Enjoy,
Adam

-----Original Message-----
From: email@hidden
[mailto:email@hidden]On Behalf Of Ricardo
Strausz
Sent: December 17, 2003 16:34
To: WOdev List List
Subject: subStrings separated by...


Hola!

This most be an easy one (for someone who knows Java);
in a validateAtribute(String value) method of an EOGenericRecord's
child, I want to check if the value have the form ABC-123456-XYZ (3
letters, dash, 6 numbers, dash, 3 alphanumeric characters). In Obj-C,
while using NSString, you simply use

NSArray anArrayOfStrings = [value componentsSeparatedByString:@"-"];

and then parse each of the 3 elements in the array.

java.lang.String does not seem to have such a method (nor any that
returns an array or vector).

Any idea on how to acomplish this.

Gracias,
Dino
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >subStrings separated by... (From: Ricardo Strausz <email@hidden>)

  • Prev by Date: Re: subStrings separated by...
  • Next by Date: Re: subStrings separated by...
  • Previous by thread: Re: subStrings separated by...
  • Next by thread: Re: subStrings separated by...
  • Index(es):
    • Date
    • Thread