# Thread: String Problem

1. ## String Problem

hi,

ok..i'm trying to work on this function which adds any missing plus signs in front of any terms that do not have one. The math equation is a string so basically if i have like 3w-y=5, i want to make it +3w-y=+5.

The way i'm looking at this is that maybe i need to place a string inside another string or maybe i can check if a term doesn't begin with one(don't know how to do this), i can insert the plus sign.

So confused
Thanks for any help and direction

2. you cant 'insert' it. but you can concatenate two strings together or even read one string character by character into a new string.

http://www.acm.uiuc.edu/webmonkeys/b...uide/2.14.html

3. ok..i understand how to read a string into a character(thought abt that) but i''m not sure how to check if a one is present before a term...i mean like for(-z) there is implicit one there...i don't understand how to check for that either.

4. Break it into logical steps. How do you do it manually? How would you turn that into code?
Code:
```look at the first portion
does it begin with a sign?
no - add one
yes - read until the next "portion" is encountered
repeat until done```
That's pretty much how you'd do it, right?
Code:
`3w + 5x = 8w`
Look at the first portion. That would be "3w". There is no sign, so add a positive sign as the default.

"+3w"

Now we encountere the beginning of a new portion, signified by some form of mathmatical gizmo. In this case, it is in fact a sign. So, we grab it, along with everything until the next "mathmatical gizmo", as the next "portion".

Repeat until done.

"+3w" "+5x" "=" "+8w"

That's what you were looking for right? Now you add a bit of complexity working with parenthesis and the like. It's up to you to decide what constitues a "portion", and what to do when you encounter a "mathmatical gizmo".

Quzah.

5. i understand the logical steps required to do this, its just that i don't know how to look at portions before the math opertaor and insert the plus sign.
The way i'm trying is to find where a plus sign is located in the string, save that location, then make a new string which adds the plus sign until the location where the plus sign is....but i don't think that right

6. Originally Posted by axe786
i understand the logical steps required to do this, its just that i don't know how to look at portions before the math opertaor and insert the plus sign.
then you prolly don't understand the logic. where do you want to insert the sign? before a............digit, right? so check before every digit. go back to the space you want and put the sign there. off the top, you can prlly use the isdigit() function. or you can make one up of your own.

isdigit() info located here

Popular pages Recent additions