Results 1 to 4 of 4

Thread: no comma on the last array

  1. #1
    Join Date
    Aug 2009
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default no comma on the last array

    I need to figure out how NOT to put a comma on the last array.

    Code:
    images : [
    	<% for(int i = 0; i< productInfolist.size(); i++){	
    	ProductInfo productInfo = (ProductInfo)productInfolist.get(i);
    	String familyDescription = productInfo.getFamilyDescription();	
    	familyDescription = DataMethods.findReplace(familyDescription,"\"","\\\"");
    	familyDescription = familyDescription.replaceAll("(\r\n|\r|\n|\n\r)", " "); %>
    	
    	["<%=CategoryInfoRetrieve.getProductDetailHeroImage(productInfo.getProduct())%>", "<%=DataMethods.findReplace(productInfo.getProductFamilyName(),"\"","\\\"")%>", "<%=familyDescription%>", "<%=productInfo.getFamilyFormatedPrice(false)%>", "<%=productInfo.getProductURL()%>"],
    	
    	<% }
    	%>
    
    	],
    Thanks
    Zach

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Just say 'No.' Er - if this is javascript (where I found this post) that would be the answer. However, it looks like you are also using asp or something server side like asp. If the server code is producing this unwanted comma, that's where you need to address it. If javascript is, and it is a string, the replace method may be used to remove it. If it is an array, an extra comma at the end denotes an additional undefined item, the array may be popped via the pop() method. If it is an object, I'm not aware of any simple way to get rid of it. All in all, it would be best to prevent it from getting there in the first place, unless it is causing no real problem, in which case - forget about it.

    By the way, just looking at the code, I'm not even sure which comma you are talking about.

    One other thing I should mention, as it may be relevant - if you were to use a regular expression to insert commas at certain points, you could use a negative look ahead to skip placing one at the end.

    Also, if you already have a string at some point with delimiters of any kind, even if they are irregular as appears to be the case here:

    Code:
    (\r\n|\r|\n|\n\r)
    in javascript the string can then be made into an array by splitting it on those delimiters, ex:

    Code:
    images: (function(s){return s.split(/\r\n|\r|\n|\n\r/);})('string to split'),
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Aug 2009
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Thanks John

    The javascript is inside a .jsp file.

    What I'm getting is
    Code:
    ["<%=CategoryInfoRetrieve.getProductDetailHeroImage(productInfo.getProduct())%>", "<%=DataMethods.findReplace(productInfo.getProductFamilyName(),"\"","\\\"")%>", "<% out.print(familyDescription); %>", "<%=productInfo.getFamilyFormatedPrice(false)%>", "<%=productInfo.getProductURL()%>"],
    ["<%=CategoryInfoRetrieve.getProductDetailHeroImage(productInfo.getProduct())%>", "<%=DataMethods.findReplace(productInfo.getProductFamilyName(),"\"","\\\"")%>", "<% out.print(familyDescription); %>", "<%=productInfo.getFamilyFormatedPrice(false)%>", "<%=productInfo.getProductURL()%>"],
    and what i need is
    Code:
    ["<%=CategoryInfoRetrieve.getProductDetailHeroImage(productInfo.getProduct())%>", "<%=DataMethods.findReplace(productInfo.getProductFamilyName(),"\"","\\\"")%>", "<% out.print(familyDescription); %>", "<%=productInfo.getFamilyFormatedPrice(false)%>", "<%=productInfo.getProductURL()%>"],
    ["<%=CategoryInfoRetrieve.getProductDetailHeroImage(productInfo.getProduct())%>", "<%=DataMethods.findReplace(productInfo.getProductFamilyName(),"\"","\\\"")%>", "<% out.print(familyDescription); %>", "<%=productInfo.getFamilyFormatedPrice(false)%>", "<%=productInfo.getProductURL()%>"]

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Yes, but how do you get what you don't want? Something (some code) must be placing the comma there. I don't see, haven't seen yet, in your posts any javascript that could be doing anything like that. The replaceAll method which I see as the most likely candidate for this isn't native javascript code, probably (if it's native anything) it's VB. If it is a custom javascript function, I'd need to see that. If it's VB or some other server code, that's where you need to look to fix it.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •