-8

I want to split Value1 and value2 from the string Value1 + value2 = Value3(Which is retrieving from excel). I don't required Value3 String. Can some one please answer.

Object[] caliculation = readCaliTable.readExcelByColName("Calculations");
    for (int i = 0; i < caliculation.length; i++) {
        System.out.println(caliculation[i]);
        String[] firstValue = caliculation[i].toString().split("\\+");
Kiran
  • 1
  • 1
  • 3
  • What is the question then? Am I missing something here? please try to clarify the question. – LazerBanana Aug 14 '17 at 14:57
  • 2
    You question is confusing. You want to split a string into three different strings? Or do you want to combine two strings into one? – Jimenemex Aug 14 '17 at 14:57
  • 2
    Do it in two steps: (1) separate left hand side from right hand side by splitting on "=", and (2) separate left hand side into operands by splitting on operators. – duffymo Aug 14 '17 at 14:57
  • I want only value1 and value2. Value3 has to ignore – Kiran Aug 14 '17 at 15:20
  • I want yhe strings which is between + – Kiran Aug 14 '17 at 15:22
  • Possible duplicate of [How to split a string in Java](https://stackoverflow.com/questions/3481828/how-to-split-a-string-in-java) – LazerBanana Aug 15 '17 at 07:31

2 Answers2

0

Try something like this:

String[] values = caliculation[i].toString().split("[+=]");

This will split the 3 values into an array of 3 elements...

values[0] // this is your Value1
values[1] // this is your Value2
Usagi Miyamoto
  • 6,196
  • 1
  • 19
  • 33
0

use something like this

  String[] firstValue ;
  String[] secondValue ;
  Object[] caliculation = readCaliTable.readExcelByColName("Calculations");
  for (int i = 0; i < caliculation.length; i++) {
      System.out.println(caliculation[i]);
      firstValue[i] = caliculation[i].toString().split("\\+")[0];
      secondValue[i] = caliculation[i].toString().split("\\+")[1].split("\\=")[0];
  }
user2862544
  • 415
  • 3
  • 13