2 Replies - 763 Views - Last Post: 29 December 2013 - 08:30 PM Rate Topic: -----

#1 hamuel   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 28-December 13

How to split string at operators

Posted 28 December 2013 - 03:02 AM

Im creating a calculator in Java.

If i have the user enter a string such as:

7+4-(18/3)/2

So far i have had to have the user enter a space between each number or operator, i don't wish to do this anymore. How would i create an array from the given string where the string is split at either a number or an operator so in this case the array would be:

[7, +, 4, -, (, 18, /, 3, ), /, 2]

(The array is of type String)

Any help would be really appreciated

Thanks :)/>

Is This A Good Question/Topic? 0
  • +

Replies To: How to split string at operators

#2 astonecipher   User is offline

  • Enterprise Software Architect
  • member icon

Reputation: 3215
  • View blog
  • Posts: 12,098
  • Joined: 03-December 12

Re: How to split string at operators

Posted 28 December 2013 - 03:43 AM

What have you tried to do?
Was This Post Helpful? 0
  • +
  • -

#3 yashwanth.c.b   User is offline

  • D.I.C Head

Reputation: 31
  • View blog
  • Posts: 234
  • Joined: 07-July 13

Re: How to split string at operators

Posted 29 December 2013 - 08:30 PM

skip the white space using a while loop.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1