Based on your thread title, my first piece of advice would be to use String.split. It's a lot more flexible than StringTokenizer.
Secondly you'll need to post some code before anyone can tell you what's wrong with it.
Pt Skaar wrote:However, I've been asked to modify the code so that it will allow for this possibility:
label=data, data1, (unknown number),label=data...etc.
What's happening is that an unknown element exception is being thrown on data1. Is there an easy way around this? Especially since the possibility of multiple entries exists in the first segment.
What, so you can have:
label=data1, data2...,label=data but not:
label=data,label=data1, data2... ?
It seems to me like you're having to clear up somebody else's badly thought-out fudge. Why couldn't the format simply be:
label=data1[,data2...];label=data[,data2...];... (semicolons for separating labels, commas for separating data elements)
it'd be a lot easier, and you could then have multiple data items anywhere you like.
Either way, the answer to your question is: Yes.
If the answer to my first question is 'yes', I'd probably try something like splitting the line initially on the first two "=" it finds (ie, line.split("=", 3)).
That will give you three portions:
1. The first label name.
2. The first label data, plus the 2nd label name, separated by commas.
3. The second label data, plus any other labels in the line, separated by commas.
It should be a fairly simple matter then to cobble those back together into a set of "label=data" elements.
But, as I said, the only reason you need to do this at all is because somebody else didn't think through the problem.
Pt Skaar wrote:The LDAP data is actually being returned like this:
CN=John Smith\\, CLF\\, LUTCF,OU=Agency Sales East Region,OU=People,DC=corp
...As for the not thought out process well, the situation causing the issue wasn't previously allowed as far as I know...and now it is hence the problem.
Right, so now you need to explain to us what it is you need to do with the above.
What is CLF? Is it an empty label, or part of the data for 'CN'?
And the same question for LUCTF.
And what is the significance of the '\\'? (I notice it doesn't follow LUTCF) Is it a data delimiter (indeed, is "\\, " the delimiter; I notice that the commas are followed by a space)?
it's difficult to suggest a solution until we know what you want.
Pt Skaar wrote:I added code to replace all the '\\,' values with ',' and that gets me LDAP data like this:
CN=John Smith, CLF, LUTCF,OU=Agency Sales East Region,OU=People,DC=corp
I would suggest replacing "\\," by something other than a comma. A + sign, for example. That would result in this:
CN=John Smith+ CLF+ LUTCF,OU=Agency Sales East Region,OU=People,DC=corp
Then you could split that on commas just like before. You'd have to have a second piece of code which split the CN data on the + sign, but I think that would be easier than trying to paste the "CN=" back onto the bits which had no name.
You would have to be careful to choose a suitable sub-delimiter, though. If the + sign could appear in a CN value then that wouldn't work. In that case you might have to look for something more obscure like the paragraph mark ¶ or the upside-down question mark ¿ or whatever.
I missed that this was an LDAP string. Commas are not the only special character that you will need to handle - LDAP has a number of them (including +). I think you would be better off looking at the classes available in JNDI (or any other LDAP handling API) and using those to handle your strings. They will probably make things a lot easier in the long run.
Paper jam tastes about as you would expect. Try some on this tiny ad: