in reply to Re: Extracting names from string
in thread Extracting names from string

The trouble is, names can contain other things than spaces and alphanumerics (as defined by your locale).

Hyphens, for example. Apostrophes. Accented characters.

Best to split on what you know (the slash and the pipe) than what you can only guess at.

dave

Replies are listed 'Best First'.
Re^3: Extracting names from string
by dimar (Curate) on Feb 09, 2005 at 02:33 UTC

    A valid consideration. In fact you will notice I added the 'dot' (in addition to alphanumerics) simply because one was in the sample provided by the OP. The (simplifying) assumptions I enumerated were guesstimates.

    If we *really* wanted to be precise, we'd want both a spec and input validation (to know what flavor of xSV we were dealing with here, and to ensure user-data was 'scrubbed' before ever getting into the file/database/whatever to begin with)

    (for example, what happens in the alien case where you get a user who has a pipe or a slash in their name ... hmm ... isn't *slash* the name of some rock band dude ... I digress).

    You should know exactly what character sequences are in your delimiter-space, and what characters are in your message-space, and the two sets should be both finite and orthogonal.

    It's always a good reminder that (at least in production code) there should be none of this such 'guesswork' involved at all. ... but close enough for a tutorial on 'split'...