0

I am a little stuck here , Need some advice please ,I have converted the csv file from blob to string and i have divided the file into columns successfully and put them into values ,

But i now further need to process my data ,Please see below .

String strc1=''; strc1=values.get(5);

strc1 contains values in the format:

Martin, Haene; (ABCD);Michi, Koerner; (DEF)

I only want to read the values inside parantheses, I cant think of a way to do that , I ve looked into trim , replace , remove ,split functions for the string , but nothing seems to do the trick.

2

You can use Pattern and Matcher classes to find values in a string:

Pattern p = Pattern.compile('\\((.+?)\\)');
Matcher m = p.matcher(stringValue);
while(m.find()) {
    String theMatch = m.group(1);
}

What you do with theMatch is up to you.

| improve this answer | |
  • Thank you for your response , I am very new to regex, I am sorry for asking very basic stuff , Can you please confirm if this is the regex pattern equivalent to round bracket() , i just tried using it and it gave me Illegal character sequence error. What i am trying to do here is String strc1=''; strc1=values.get(5); strc1 contains values in the format: Martin, Haene; (ABCD);Michi, Koerner; (DEF) . I want to remove all text except for the one inside the bracket which is ABCD; DEF . – Natasha Jul 27 '17 at 21:10
  • @Natasha I was missing some characters. Look at my updated answer. The other solution should probably work as well. – sfdcfox Jul 27 '17 at 21:14
0

Try to use the function replaceAll.

replaceAll(regExp, replacement)

Replaces each substring of a string that matches the regular expression regExp with the replacement sequence replacement.

An example:

String s1 = '(ABCD)';
String s2 = s1.replaceAll('[()]', '');
system.debug(s2);

The result should be ABCD

Hope this helps

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.