Skip to main content
added 204 characters in body
Source Link
BarCotter
  • 12.4k
  • 4
  • 38
  • 58

The code below will get the text from within the brackets. The code makes use of some String methods

String eDescription = 'This is (the test) text';
Integer openingIndex = eDescription.indexOf('(');
Integer closingIndex = eDescription.indexOf(')');
String textInBrackets = eDescription.subString(openingIndex + 1, closingIndex);

Using @Sovereigntys suggestion of using substringBetween then the code becomes:

String eDescription = 'This is (the test) text';
String textInBrackets = eDescription. substringBetween('(', ')');

FYI: Both ways will find the first instance of '(' and ')'.

  • Input: 'This is (the test) text', Output: 'the test'
  • Input: 'This is (the test) (text)', Output: 'the test'

The code below will get the text from within the brackets. The code makes use of some String methods

String eDescription = 'This is (the test) text';
Integer openingIndex = eDescription.indexOf('(');
Integer closingIndex = eDescription.indexOf(')');
String textInBrackets = eDescription.subString(openingIndex + 1, closingIndex);

Using @Sovereigntys suggestion of using substringBetween then the code becomes:

String eDescription = 'This is (the test) text';
String textInBrackets = eDescription. substringBetween('(', ')');

The code below will get the text from within the brackets. The code makes use of some String methods

String eDescription = 'This is (the test) text';
Integer openingIndex = eDescription.indexOf('(');
Integer closingIndex = eDescription.indexOf(')');
String textInBrackets = eDescription.subString(openingIndex + 1, closingIndex);

Using @Sovereigntys suggestion of using substringBetween then the code becomes:

String eDescription = 'This is (the test) text';
String textInBrackets = eDescription. substringBetween('(', ')');

FYI: Both ways will find the first instance of '(' and ')'.

  • Input: 'This is (the test) text', Output: 'the test'
  • Input: 'This is (the test) (text)', Output: 'the test'
deleted 4 characters in body
Source Link
BarCotter
  • 12.4k
  • 4
  • 38
  • 58

The code below will get the text from within the brackets. The code makes use of some String methodsString methods

String eDescription = 'This is (the test) text';
Integer openingIndex = eDescription.indexOf('(');
Integer closingIndex = eDescription.indexOf(')');
String textInBrackets = eDescription.subString(openingIndex + 1, closingIndex);

Using @Sovereigntys suggestion of using substringBetween then the code becomes:

String eDescription = 'This is (the test) text';
String textInBrackets = eDescription. substringBetween('(', ')');

The code below will get the text from within the brackets. The code makes use of some String methods

String eDescription = 'This is (the test) text';
Integer openingIndex = eDescription.indexOf('(');
Integer closingIndex = eDescription.indexOf(')');
String textInBrackets = eDescription.subString(openingIndex + 1, closingIndex);

The code below will get the text from within the brackets. The code makes use of some String methods

String eDescription = 'This is (the test) text';
Integer openingIndex = eDescription.indexOf('(');
Integer closingIndex = eDescription.indexOf(')');
String textInBrackets = eDescription.subString(openingIndex + 1, closingIndex);

Using @Sovereigntys suggestion of using substringBetween then the code becomes:

String eDescription = 'This is (the test) text';
String textInBrackets = eDescription. substringBetween('(', ')');
Source Link
BarCotter
  • 12.4k
  • 4
  • 38
  • 58

The code below will get the text from within the brackets. The code makes use of some String methods

String eDescription = 'This is (the test) text';
Integer openingIndex = eDescription.indexOf('(');
Integer closingIndex = eDescription.indexOf(')');
String textInBrackets = eDescription.subString(openingIndex + 1, closingIndex);