Service Desk Practitioners Forum
cancel

spliting a string into two fields on service pages

SOLVED
Go to solution
Highlighted
Akies
Outstanding Contributor.

spliting a string into two fields on service pages

Hi All,

One more query from my side..

I want to split a text field in the service call split into different fields on the web pages with separator as comma(,).
actually I am capturing users details on one text field(due to field restriction) but I have provided different fields on the fron-end which gets concatenated with comma as separator between them in this one text field.
Similarly I want to display this user's details on the view page in different fields(same as while capturing them on the web).

I tried using split() function but its not working..may be I am using some wrong syntax.

Can anyone help me?? pls :-(

Regards,
Akhil
4 REPLIES
Radovan Skolnik
Acclaimed Contributor.
Solution

Re: spliting a string into two fields on service pages

This requires a bit of slight Java coding. There are many possibilities:

1. You can use indexOf(char c) method of String class to find the position of ',' and then use substring method
2. There is a class called StringTokenizer in java.util package that can split String instances - so you'd just create one StringTokenizer st = new StringTokenizer(your_string, ",") and then just call nextToken() on it twice.
3. In newer runtimes (I think from 1.4 or 1.5) there's possibility to use regular expressions that can do you the service.

Hope this helps...
Akies
Outstanding Contributor.

Re: spliting a string into two fields on service pages

Hurry...thanks rod..Well I have'nt tried this yet but now I am atleast satisfied that we can achieve this...
Now it will be a great help if you could give me an example of the same in some details...pls

Regards,
Akhil
Radovan Skolnik
Acclaimed Contributor.

Re: spliting a string into two fields on service pages

OK. I'll try to explain the thing with StringTokenizer. Here's a snippet that you could use:

String firstPart;
String secondPart;
String valueFromSD = serviceDeskEntity.getField(); // replace with real SD entity instance and real method name for retrieving the field (entity and field where you store that value)
StringTokenizer st = new StringTokenizer(valueFromSD, ","); // create StringTokenizer instance with comma as delimiter
if (st.countTokens() != 2) {
// do something here - the value is not formatted as expected - i.e. has not got 2 parts
} else {
firstPart = st.nextToken(); // get the part in front of comma
secondPart = st.nextToken(); // get the part after comma
}

Now just initialize 2 controls you provide on the front-end with firstPart and secondPart.

Is that clear?
Akies
Outstanding Contributor.

Re: spliting a string into two fields on service pages

Thanks...I have used substring for the same.

thanks again..

Regards,
Akhil