Author |
Message |
tum_twish
|
Posted: Thu Apr 17, 2003 9:58 am Post subject: 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. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
jamez
|
Posted: Thu Apr 17, 2003 10:22 am Post subject: (No subject) |
|
|
hmm can i see teh code? |
|
|
|
|
|
Lone]2
|
Posted: Thu Apr 17, 2003 10:28 am Post subject: (No subject) |
|
|
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
|
Posted: Thu Apr 17, 2003 10:41 am Post subject: (No subject) |
|
|
code: |
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
|
Posted: Thu Apr 17, 2003 10:42 am Post subject: (No subject) |
|
|
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
|
Posted: Thu Apr 17, 2003 10:47 am Post subject: (No subject) |
|
|
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 |
|
|
|
|
|
Office of the Registar
|
Posted: Thu Apr 17, 2003 2:29 pm Post subject: (No subject) |
|
|
that's the kind of attitude that should get you kicked out of this field tomako |
|
|
|
|
|
Office of the Registar
|
Posted: Thu Apr 17, 2003 2:43 pm Post subject: (No subject) |
|
|
i can't beleive you guys are just wasting time like this |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Leafs Fan
|
Posted: Thu Apr 17, 2003 2:45 pm Post subject: (No subject) |
|
|
course heheh |
|
|
|
|
|
Tony
|
Posted: Thu Apr 17, 2003 2:56 pm Post subject: (No subject) |
|
|
you can use substrings to get rid of the last character (the unwanted +)
word := word(1..*-1)
then you add "= whatever" |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
yuethomas
|
Posted: Thu Apr 17, 2003 10:37 pm Post subject: (No subject) |
|
|
Or, don't append the plus sign... do an if statement for it
code: | 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. ~=? |
|
|
|
|
|
|