
-----------------------------------
tum_twish
Thu Apr 17, 2003 9:58 am

String Substitution
-----------------------------------
I have string that displays the sum of various numbers.  The string is concatenated in a loop.  However, at the end of the calculation, an extra "+" displays.  How can I remove that plus sign?

ie.

2+5+7+9+10+=33

How do I remove the last + sign? Thanx.

-----------------------------------
jamez
Thu Apr 17, 2003 10:22 am


-----------------------------------
hmm can i see teh code?

-----------------------------------
Lone]2
Thu Apr 17, 2003 10:28 am


-----------------------------------
maybe you're just exiting the loop too late.
try exiting the loop sooner so that the "+" wont show up at the end of your equation

-----------------------------------
tum_twish
Thu Apr 17, 2003 10:41 am


-----------------------------------

function Sum_Of_The_Proper_Factors (I_number : int, B_flag : boolean) : int

    %This function calculates the sum of the proper factors of a number
    %The function requires the number
    %The function returns the sum of proper factors back.

    var I_sum : int := 0
    S_factorsString := ""
    for I_factor : 1 .. (I_number - 1)
        if I_number mod I_factor = 0 then
            I_sum := I_sum + I_factor
            S_factorsString := S_factorsString + intstr (I_factor) + "+"
        end if
    end for
    result I_sum
end Sum_Of_The_Proper_Factors

S_sumOfFactorsString := intstr (Sum_Of_The_Proper_Factors (I_number,
            B_flag))
GUI.SetText (I_factorsOutput, S_factorsString + "=" +
                S_sumOfFactorsString)


-----------------------------------
Blade
Thu Apr 17, 2003 10:42 am


-----------------------------------
please, if you are having problems with code or anything like that, please post the code... or even give an example of what you want... in your case the example wont help much so please post the code...

-----------------------------------
tomako
Thu Apr 17, 2003 10:47 am


-----------------------------------
im not good at programming, but logically speaking, y dont u just forget about displaying the "+"s?
u can put a space or sumthing instead :D

-----------------------------------
Office of the Registar
Thu Apr 17, 2003 2:29 pm


-----------------------------------
that's the kind of attitude that should get you kicked out of this field tomako :)

-----------------------------------
Office of the Registar
Thu Apr 17, 2003 2:43 pm


-----------------------------------
i can't beleive you guys are just wasting time like this

-----------------------------------
Leafs Fan
Thu Apr 17, 2003 2:45 pm


-----------------------------------
course heheh

-----------------------------------
Tony
Thu Apr 17, 2003 2:56 pm


-----------------------------------
you can use substrings to get rid of the last character (the unwanted +)

word := word(1..*-1)

then you add "= whatever"

-----------------------------------
yuethomas
Thu Apr 17, 2003 10:37 pm


-----------------------------------
Or, don't append the plus sign... do an if statement for it

    for I_factor : 1 .. (I_number - 1) 
        if I_number mod I_factor = 0 then 
            I_sum := I_sum + I_factor 
            S_factorsString := S_factorsString + intstr (I_factor)
%--
            if I_factor (notequal) I_Number - 1 then
                S_factorsString := S_factorsString + "+"
            end if
%--
        end if 
    end for

notequal: I forgot the operator for it. ~=?
