Important Notice from AspDotNetStorefront
It is with dismay that we report that we have been forced, through the action of hackers, to shut off write-access to this forum. We are keen to leave the wealth of material available to you for research. We have opened a new forum from which our community of users can seek help, support and advice from us and from each other. To post a new question to our community, please visit: http://forums.vortx.com
Results 1 to 5 of 5

Thread: Coding Question

  1. #1
    BFG 9000 is offline Senior Member
    Join Date
    Oct 2006
    Location
    South UK
    Posts
    882

    Question Coding Question

    Hi All,

    I'm looking for a little bit of code help.
    I have the following, which produces a pipe seperated list of values:-
    C#/VB.NET Code:

         
    if (amtlist == String.Empty) amtlist = (i.m_Price*100).ToString();
         else 
    amtlist += "|" + (i.m_Price*100); 
    An example output might look like this :-
    C#/VB.NET Code:
    262.0000|573.5700|624.5000|67.0000 
    I'm looking to modify it so that it removes the decimal point & anything following it, giving an output like this :-
    C#/VB.NET Code:
    262|573|624|67 
    It looks like a fairly simple tweak but unfortunately, this is not my language....

    Can anyone help?


    TTFN

    BFG

  2. #2
    AspDotNetStorefront Staff - Scott's Avatar
    AspDotNetStorefront Staff - Scott is offline Administrator
    Join Date
    Mar 2007
    Location
    Ashland, OR
    Posts
    2,390

    Default

    If you know for sure that i.m_Price will always have a decimal in it, you can do something like this after you've turned it into a string but before you add it to amtlist:

    Code:
    i.m_Price = i.m_Price.Substring(0, i.m_Price.IndexOf("."));

  3. #3
    BFG 9000 is offline Senior Member
    Join Date
    Oct 2006
    Location
    South UK
    Posts
    882

    Default

    Thanks Scott

    Looks (to my amatuer eye) like I might need a minus 1 in there like this?
    C#/VB.NET Code:
    i.m_Price i.m_Price.Substring(0, (i.m_Price.IndexOf(".")-1)); 


    Also - in the same xmlpackage, I'm having the following problem.
    I have the following code :-
    C#/VB.NET Code:
         if (namelist == String.Empty) namelist i.m_ProductName;
         else 
    namelist += "|" i.m_ProductName
    I'm trying to insert a UrlEncode as indicated below :-

    C#/VB.NET Code:
         if (namelist == String.Empty) namelist UrlEncode(i.m_ProductName);
         else 
    namelist += "|" UrlEncode(i.m_ProductName); 
    But it keeps throwing context errors, I've tried all of the following to no avail :-

    C#/VB.NET Code:
    System.Web.HttpContext.Current.Server.UrlEncode(i.m_ProductName)
    System.Web.Server.UrlEncode(i.m_ProductName)
    System.Web.UrlEncode(i.m_ProductName)
    HttpContext.Current.Server.UrlEncode(i.m_ProductName)
    Server.UrlEncode(i.m_ProductName
    Is anyone able to offer any help?


    TTFN

    BFG

  4. #4
    AspDotNetStorefront Staff - Scott's Avatar
    AspDotNetStorefront Staff - Scott is offline Administrator
    Join Date
    Mar 2007
    Location
    Ashland, OR
    Posts
    2,390

    Default

    Nope, don't need the -1. The index count starts at 0 so counting to the decimal (1 place after the chars you want to keep) is actually going to count the number of chars you want.

    Not sure on the context errors, I'll have a couple of the guys here take a look.

  5. #5
    BFG 9000 is offline Senior Member
    Join Date
    Oct 2006
    Location
    South UK
    Posts
    882

    Default

    Ahh - Genius!

    Thanks Scott.



    TTFN

    BFG