You need to sign in to do that
Don't have an account?
bluecap
How to split a string containing square brackets..?
Hi all,
Im trying to split a string that has a mulitple sets of text enclosed in square brackets. For some reason its not splitting them like I think that it should.. Can anyone tell what Im doing incorrectly?
String tmpBody = 'TestBamo[#taskdate:2016-11-15 00:00:00][#hitcriteria:Proactively schedule a branch visit]';
String[] bodyList = tmpBody.split('\\\[(.*?)\\]');
for(String s : bodyList){
system.debug('------>'+s);
}
Which returns...
s[0] = TestBamo
I would think this should return the following...
s[0] = [#taskdate:2016-11-15 00:00:00]
s[1] = [#hitcriteria:Proactively schedule a branch visit]
Im trying to split a string that has a mulitple sets of text enclosed in square brackets. For some reason its not splitting them like I think that it should.. Can anyone tell what Im doing incorrectly?
String tmpBody = 'TestBamo[#taskdate:2016-11-15 00:00:00][#hitcriteria:Proactively schedule a branch visit]';
String[] bodyList = tmpBody.split('\\\[(.*?)\\]');
for(String s : bodyList){
system.debug('------>'+s);
}
Which returns...
s[0] = TestBamo
I would think this should return the following...
s[0] = [#taskdate:2016-11-15 00:00:00]
s[1] = [#hitcriteria:Proactively schedule a branch visit]
If u need output like this, try below code
|DEBUG|------>TestBamo
|DEBUG|------>[#taskdate:2016-11-15 00:00:00]
|DEBUG|------>[#hitcriteria:Proactively schedule a branch visit]
If this is enough(without starting [ ), try below code
|DEBUG|------>TestBamo
|DEBUG|------>#taskdate:2016-11-15 00:00:00]
|DEBUG|------>#hitcriteria:Proactively schedule a branch visit]
Please let me know if it helps.
Thanks,
Nagendra Prasad