Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
String Substitution
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.

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)

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

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)

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. ~=?
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 11 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: