Hello, I am new with c#. I need help in splitting the operators and operand in two different arrays. For example 4+5-3-6+7 is an input string, so in this i want 4,5,3,6,7 in one array and +,- in another array . can anyone please help me out ?
rutul
0
Newbie Poster
Recommended Answers
Jump to PostSplit is a function of string. But it needs a consistent characater. What Mono was saying was, add a space between each character then you can split on the space character.
You could do it like thisstring val = "4+5-3-6+7"; StringBuilder sb = new StringBuilder(); for(int …
Jump to Post@mono_jit23: Your code would only split the values into a single array, the OP needs Numbers in one array and operators in another.
@rutul: The problem you are going to have is dimensioning your arrays as you wont know how many Numbers and how many operators your string holds …
Jump to PostThis a bit of an implementation as Ryshad suggested. I used the Queu class here, but
List, Stack, or Array class may fit in as well, depending on your needs.static void Main(string[] args) { string str = "4+5-3-6+7"; // make two queus which can hold chars …
All 10 Replies
mono_jit23
1
Junior Poster in Training
Lesone
0
Newbie Poster
edepperson
8
Newbie Poster
Geekitygeek
480
Nearly a Posting Virtuoso
ddanbe
commented:
Just plain good!
+7
ddanbe
2,724
Professional Procrastinator
Featured Poster
rutul
0
Newbie Poster
ddanbe
2,724
Professional Procrastinator
Featured Poster
mono_jit23
1
Junior Poster in Training
Momerath
1,327
Nearly a Senior Poster
Featured Poster
mono_jit23
1
Junior Poster in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.