You need to sign in to do that
Don't have an account?
Nageswara reddy
Having trouble with String.Split using a semi-colon
HI all,
I am facing problem with string .Split using a semi-colon
String address=add2;
address=Abbyville,null,Kansas,92274|1520 Malley Road,Anchorage,Alaska,99501|
string[] spilt= address.split('\\;'); or String[]split=address.split(';');
for(string s: spilt)
{
system.debug('***********'+s);
}
i am getting like this way
5] 03:18:49.816 (816967000)|HEAP_ALLOCATE|[375]|Bytes:4 03:18:49.817 (817007000)|HEAP_ALLOCATE|[375]|Bytes:8 03:18:49.817 (817015000)|HEAP_ALLOCATE|[375]|Bytes:4 03:18:49.817 (817047000)|HEAP_ALLOCATE|[375]|Bytes:76 03:18:49.817 (817063000)|VARIABLE_SCOPE_BEGIN|[375]|spilt|LIST<String>|true|false 03:18:49.817 (817092000)|VARIABLE_ASSIGNMENT|[375]|spilt|["Abbyville,null,Kansa (48 more) ..."]|0x56145e09 03:18:49.817 (817125000)|SYSTEM_METHOD_ENTRY|[376]|LIST<String>.iterator() 03:18:49.817 (817269000)|SYSTEM_METHOD_EXIT|[376]|LIST<String>.iterator() 03:18:49.817 (817293000)|SYSTEM_METHOD_ENTRY|[376]|system.ListIterator.hasNext() 03:18:49.817 (817309000)|HEAP_ALLOCATE|[376]|Bytes:5 03:18:49.817 (817323000)|SYSTEM_METHOD_EXIT|[376]|system.ListIterator.hasNext() 03:18:49.817 (817339000)|HEAP_ALLOCATE|[376]|Bytes:68 03:18:49.817 (817360000)|VARIABLE_SCOPE_BEGIN|[376]|s|String|false|false 03:18:49.817 (817380000)|VARIABLE_ASSIGNMENT|[376]|s|"Abbyville,null,Kansa (48 more) ..." 03:18:49.817 (817392000)|STATEMENT_EXECUTE|[377] 03:18:49.817 (817403000)|STATEMENT_EXECUTE|[378] 03:18:49.817 (817413000)|HEAP_ALLOCATE|[378]|Bytes:11 03:18:49.817 (817430000)|HEAP_ALLOCATE|[378]|Bytes:79 03:18:49.817 (817445000)|SYSTEM_METHOD_ENTRY|[378]|System.debug(ANY) 03:18:49.817 (817480000)|USER_DEBUG|[378]|DEBUG|***********Abbyville,null,Kansas,92274|1520 Malley Road,Anchorage,Ala
Hi
you are looping through 'spilt' which splits based on '\\' which i do not find in your string.
Please loop through 'split' and verify.
Please refer the code below. For the below
String address= 'Abbyville,null,Kansas,92274|1520 Malley Road,Anchorage,Alaska,99501|';
String []splits =address.split(';');
for(string s: splits)
{
system.debug('***********'+s);
}
Debug log ouput
17:42:01:038 USER_DEBUG [6]|DEBUG|***********Abbyville,null,Kansas,92274|
17:42:01:038 USER_DEBUG [6]|DEBUG|***********1520 Malley Road,Anchorage,Alaska,99501|
I dont see anything wrong. Its getting split for ';'. What else is needed?
but same code when i use in apex apec class it'not splitting., see the above debug log . in the console 'it's working fine