Given exactly the constraints you've given, I think the easiest way would be to convert the delimiter as read from the config file to the one you need to use. You might do this with a series of replaceAll() calls on the
string you read in, or you might set up a HashMap or whatever if you have to do that conversion many times.
Of course, if "\t" is the only escaped delimiter you'll ever see and all others will be single characters, then you only have to do one conversion.
Do you have control of the config file. If so, you might encode the delimiter differently.
If the file is XML, you could use CDATA or a single encoded char for the delimiter: <delimiter> </delimiter>Could you put the ascii code for the delimiter in the file instead? delimiter=09You could encode the delimiter using some scheme for which a decoder already exists. For instnce a URLDecoder() will take %09 and convert it to a TAB. (%09 is ok to have as an XML value without escaping any of the chars.)If the file format is readable by a Properties object, then just use Properties.load(). That automatically does \t conversion. But I don't know of anything built into the base classes that will convert \t to a TAB, \f to a FORMFEED, etc. in a String that's already in memory without enumerating all the ones you might see in your application.
Stan:
dlm = " ".replace(" ", "/" + dlm ); I think you meant replaceAll() or replaceFirst(). Also, I think you were thinking of a '\' instead of a '/'.
Stan:
The hard-coded "/" plus the one in the config file makes "//t" which regex will recognize as tab. Maybe. Try it and let me know. If it works it should accept anything that regex can recognize with a leading / I'm not positive it won't work, but I don't think String addition really works like that. If you change your source code to...
dlm = " ".replace(" ", "\" + dlm);
...the compiler would complain that you have an open String literal because it would start think that the \" sequence meant you wanted your string to start quote-space-plus-space-dee-ell-emm-paren-semi. If you change it to...
dlm = " ".replace(" ", "\\" + dlm);
...when dlm was read in as backslash-tee, you'll have dlm equals to backslash-backslash-tee. Ok, but then what would you do with it to replace that with a TAB? One of us must be missing something.
Ryan
[ May 20, 2005: Message edited by: Ryan McGuire ]