Service Virtualization

 View Only

 How to split a string using delimeter

Nagasree Devarakonda's profile image
Nagasree Devarakonda posted Jan 06, 2023 02:16 PM
Hi,

I am trying to split a string using delimeter "." using below code in match script but split function is not working. Can you please suggest what to use to split a string using delimeter and trying to fetch string at 0th position.

Here length() function is working as expected, but split function is not working.

Parameter value:
_id = DPLAN01R.20210101

Code:
String ID = incomingRequest.getArguments().get("_id");
_logger.debug("debug data value {}", ID);
_logger.debug("debug data value {}", ID.length());
String[] data = ID.split(".");
_logger.debug("debug individual data value {}", data[0]); 
Harish Tammireddygari's profile image
Broadcom Employee Harish Tammireddygari
Hi,

You need to escape the dot:
String[] data = ID.split("\\.");

Thanks,
Harish T
Nagasree Devarakonda's profile image
Nagasree Devarakonda
Thanks for the update. Will verify by adding escape sequence.