0

How do I split a string like (int,x) into [(, int, , x, )]

GBlodgett
  • 12,630
  • 4
  • 27
  • 42
mastercool
  • 363
  • 7
  • 23
  • You mean like `str.split("");`? This will split on every character – GBlodgett Jan 16 '19 at 04:21
  • 3
    you need to add more explanation to your question & illustrate by an example by taking a sample input & expected output. – Sabir Khan Jan 16 '19 at 04:22
  • You are confused in asking what you wanna ask :) – Vishwa Ratna Jan 16 '19 at 04:28
  • And what have you tried so far? – Nicholas K Jan 16 '19 at 06:07
  • Please show your attempt at solving the problem, define what you mean exactly by special characters (is `_` also a special character for example) and tell what should happen if there are multiple of these special characters next to each other, e.g. `(int,,x)` – Jerry Jan 16 '19 at 07:50

1 Answers1

8

With your expected output, you can use \b to split your string and get the expected output,

Here is the Java code,

String s = "(int,x)";
System.out.println(Arrays.toString(s.split("\\b")));

Prints,

[(, int, ,, x, )]
Pushpesh Kumar Rajwanshi
  • 17,308
  • 2
  • 17
  • 34