Java

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • How to see if there is the end of the array

    5 answers - 1467 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    Hallo,
    I have question about the work with array.
    I have a #for-loop in my template like this:
    #foreach ($column in $column-detail-data)
    "${column.getChild("header").Text}",
    #end
    and I want to now if I'm on the end of the array $column,
    because of the comma at the end of the command.
    If there is no more elements, I don't want to set comma any more.
    Can you give me some advice please?
    Thanks for reply.
    Vitali
    IPS Software GmbH
    Isaac-Fulda-Allee 9
    55124 Mainz
    tel: +49.6131.37577.0
    fax: +49.6131.37577.55
    -
    Niederlassung Munchen:
    Grafinger Str. 2
    81671 Munchen
    tel.: +49.89.18926780
    fax.: +49.89.18926808
    -
    url: http://www.ips-software.de
    Diese e-Mail enthaelt vertrauliche und/oder rechtlich geschuetzte
    Informationen. Wenn Sie nicht der richtige Adressat sind oder diese
    e-Mail irrtuemlich erhalten haben informieren Sie bitte sofort den
    Absender und vernichten Sie diese e-Mail. Das unerlaubte Kopieren
    sowie die unbefugte Weitergabe dieser e-Mail ist nicht gestattet.
    -
    This e-mail contains confidential and/or proprietary information.
    If you are not the intended recipient or if you received the e-Mail
    by mistake we ask you to notify the sender immediately and destroy
    this e-Mail. The unauthorized reproduction or distribution of this
    e-Mail is prohibited.
  • No.1 | | 1655 bytes | |

    you know that there is a counter of loop index named "velocityCount".
    you can find $column.getLength() of the array.
    that is it.

    7/22/05, Minor, Vitali <Vitali.Minor (AT) ips-software (DOT) dewrote:

    Hallo,

    I have question about the work with array.

    I have a #for-loop in my template like this:

    #foreach ($column in $column-detail-data)

    "${column.getChild("header").Text}",

    #end

    and I want to now if I'm on the end of the array $column,

    because of the comma at the end of the command.

    If there is no more elements, I don't want to set comma any more.

    Can you give me some advice please?

    Thanks for reply.

    Vitali

    IPS Software GmbH
    Isaac-Fulda-Allee 9
    55124 Mainz
    tel: +49.6131.37577.0
    fax: +49.6131.37577.55
    -
    Niederlassung Munchen:
    Grafinger Str. 2
    81671 Munchen
    tel.: +49.89.18926780
    fax.: +49.89.18926808
    -
    url: http://www.ips-software.de

    Diese e-Mail enthaelt vertrauliche und/oder rechtlich geschuetzte
    Informationen. Wenn Sie nicht der richtige Adressat sind oder diese
    e-Mail irrtuemlich erhalten haben informieren Sie bitte sofort den
    Absender und vernichten Sie diese e-Mail. Das unerlaubte Kopieren
    sowie die unbefugte Weitergabe dieser e-Mail ist nicht gestattet.
    -
    This e-mail contains confidential and/or proprietary information.
    If you are not the intended recipient or if you received the e-Mail
    by mistake we ask you to notify the sender immediately and destroy
    this e-Mail. The unauthorized reproduction or distribution of this
    e-Mail is prohibited.
  • No.2 | | 1936 bytes | |

    The simplest solution is to prefix the comma:

    #set( $sep = "" )
    #foreach ($column in $column-detail-data)

    $sep"${column.getChild("header").Text}"

    #set( $sep = ", " )
    #end

    This is fully independant of any counter and end of array.

    :) Christoph Reck

    Minor, Vitali wrote:
    Hallo,

    I have question about the work with array.

    I have a #for-loop in my template like this:

    #foreach ($column in $column-detail-data)

    "${column.getChild("header").Text}",

    #end

    and I want to now if I'm on the end of the array $column,

    because of the comma at the end of the command.

    If there is no more elements, I don't want to set comma any more.

    Can you give me some advice please?

    Thanks for reply.

    Vitali

    IPS Software GmbH
    Isaac-Fulda-Allee 9
    55124 Mainz
    tel: +49.6131.37577.0
    fax: +49.6131.37577.55
    -
    Niederlassung Munchen:
    Grafinger Str. 2
    81671 Munchen
    tel.: +49.89.18926780
    fax.: +49.89.18926808
    -
    url: http://www.ips-software.de

    Diese e-Mail enthaelt vertrauliche und/oder rechtlich geschuetzte
    Informationen. Wenn Sie nicht der richtige Adressat sind oder diese
    e-Mail irrtuemlich erhalten haben informieren Sie bitte sofort den
    Absender und vernichten Sie diese e-Mail. Das unerlaubte Kopieren
    sowie die unbefugte Weitergabe dieser e-Mail ist nicht gestattet.
    -
    This e-mail contains confidential and/or proprietary information.
    If you are not the intended recipient or if you received the e-Mail
    by mistake we ask you to notify the sender immediately and destroy
    this e-Mail. The unauthorized reproduction or distribution of this
    e-Mail is prohibited.

    To unsubscribe, e-mail: velocity-user-unsubscribe (AT) jakarta (DOT) apache.org
    For additional commands, e-mail: velocity-user-help (AT) jakarta (DOT) apache.org
  • No.3 | | 3692 bytes | |

    Christoph's simplest solution works perfectly :)
    but if you want to separate each column with , and the last one with
    "and" here is a way to do it
    Example: "java","perl","c++" and "xul"
    more complicated though

    #set( $len = $column-detail-data.length )
    #foreach($column in $column-detail-data)
    #set( $velocityCount2 = $velocityCount + 1 )
    #set( $len2 = $len - 1 )
    "${column.getChild("header").Text}"#if ($len2 == $velocityCount)
    and#elseif ($len $velocityCount2),#end
    #end

    Jeff

    Christoph Reck wrote:

    The simplest solution is to prefix the comma:

    #set( $sep = "" )
    #foreach ($column in $column-detail-data)

    $sep"${column.getChild("header").Text}"

    #set( $sep = ", " )
    #end

    This is fully independant of any counter and end of array.

    :) Christoph Reck
    --
    Minor, Vitali wrote:
    >
    >Hallo,
    >>

    >
    >>

    >I have question about the work with array.
    >>

    >I have a #for-loop in my template like this:
    >>

    >
    >>

    >#foreach ($column in $column-detail-data)
    >>

    >"${column.getChild("header").Text}",
    >>

    >#end
    >>

    >
    >>

    >and I want to now if I'm on the end of the array $column,
    >>

    >because of the comma at the end of the command.
    >>

    >
    >>

    >If there is no more elements, I don't want to set comma any more.
    >>

    >
    >>

    >Can you give me some advice please?
    >>

    >
    >>

    >Thanks for reply.
    >>

    >
    >>

    >Vitali
    >>
    >>
    >>

    >
    >IPS Software GmbH
    >Isaac-Fulda-Allee 9
    >55124 Mainz
    >tel: +49.6131.37577.0
    >fax: +49.6131.37577.55
    >-
    >Niederlassung Munchen:
    >Grafinger Str. 2
    >81671 Munchen
    >tel.: +49.89.18926780
    >fax.: +49.89.18926808
    >-
    >url: http://www.ips-software.de
    >
    >Diese e-Mail enthaelt vertrauliche und/oder rechtlich geschuetzte
    >Informationen. Wenn Sie nicht der richtige Adressat sind oder diese
    >e-Mail irrtuemlich erhalten haben informieren Sie bitte sofort den
    >Absender und vernichten Sie diese e-Mail. Das unerlaubte Kopieren
    >sowie die unbefugte Weitergabe dieser e-Mail ist nicht gestattet.
    >-
    >This e-mail contains confidential and/or proprietary information.
    >If you are not the intended recipient or if you received the e-Mail
    >by mistake we ask you to notify the sender immediately and destroy
    >this e-Mail. The unauthorized reproduction or distribution of this
    >e-Mail is prohibited.
    >>

    >
    >


    To unsubscribe, e-mail: velocity-user-unsubscribe (AT) jakarta (DOT) apache.org
    For additional commands, e-mail: velocity-user-help (AT) jakarta (DOT) apache.org

    To unsubscribe, e-mail: velocity-user-unsubscribe (AT) jakarta (DOT) apache.org
    For additional commands, e-mail: velocity-user-help (AT) jakarta (DOT) apache.org
  • No.4 | | 3418 bytes | |

    Checkout the IteratorTool which should address your request:

    :) Christoph Reck

    Jean Francois Chamard wrote:
    Christoph's simplest solution works perfectly :)
    but if you want to separate each column with , and the last one with
    "and" here is a way to do it
    Example: "java","perl","c++" and "xul"
    more complicated though

    #set( $len = $column-detail-data.length )
    #foreach($column in $column-detail-data)
    #set( $velocityCount2 = $velocityCount + 1 )
    #set( $len2 = $len - 1 )
    "${column.getChild("header").Text}"#if ($len2 == $velocityCount)
    and#elseif ($len $velocityCount2),#end
    #end

    Jeff

    Christoph Reck wrote:

    >The simplest solution is to prefix the comma:
    >>

    >#set( $sep = "" )
    >#foreach ($column in $column-detail-data)
    >>

    >$sep"${column.getChild("header").Text}"
    >>

    >#set( $sep = ", " )
    >#end
    >>

    >This is fully independant of any counter and end of array.
    >>

    >:) Christoph Reck
    >>
    >>

    >Minor, Vitali wrote:
    >>

    Hallo,

    I have question about the work with array.

    I have a #for-loop in my template like this:

    #foreach ($column in $column-detail-data)

    "${column.getChild("header").Text}",

    #end

    and I want to now if I'm on the end of the array $column,

    because of the comma at the end of the command.

    If there is no more elements, I don't want to set comma any more.

    Can you give me some advice please?

    Thanks for reply.

    Vitali

    IPS Software GmbH
    Isaac-Fulda-Allee 9
    55124 Mainz
    tel: +49.6131.37577.0
    fax: +49.6131.37577.55
    -
    Niederlassung Munchen:
    Grafinger Str. 2
    81671 Munchen
    tel.: +49.89.18926780
    fax.: +49.89.18926808
    -
    url: http://www.ips-software.de

    Diese e-Mail enthaelt vertrauliche und/oder rechtlich geschuetzte
    Informationen. Wenn Sie nicht der richtige Adressat sind oder diese
    e-Mail irrtuemlich erhalten haben informieren Sie bitte sofort den
    Absender und vernichten Sie diese e-Mail. Das unerlaubte Kopieren
    sowie die unbefugte Weitergabe dieser e-Mail ist nicht gestattet.
    -
    This e-mail contains confidential and/or proprietary information.
    If you are not the intended recipient or if you received the e-Mail
    by mistake we ask you to notify the sender immediately and destroy
    this e-Mail. The unauthorized reproduction or distribution of this
    e-Mail is prohibited.

    >>
    >>

    >
    >To unsubscribe, e-mail: velocity-user-unsubscribe (AT) jakarta (DOT) apache.org
    >For additional commands, e-mail: velocity-user-help (AT) jakarta (DOT) apache.org


    To unsubscribe, e-mail: velocity-user-unsubscribe (AT) jakarta (DOT) apache.org
    For additional commands, e-mail: velocity-user-help (AT) jakarta (DOT) apache.org

    To unsubscribe, e-mail: velocity-user-unsubscribe (AT) jakarta (DOT) apache.org
    For additional commands, e-mail: velocity-user-help (AT) jakarta (DOT) apache.org
  • No.5 | | 1936 bytes | |

    The simplest solution is to prefix the comma:

    #set( $sep = "" )
    #foreach ($column in $column-detail-data)

    $sep"${column.getChild("header").Text}"

    #set( $sep = ", " )
    #end

    This is fully independant of any counter and end of array.

    :) Christoph Reck

    Minor, Vitali wrote:
    Hallo,

    I have question about the work with array.

    I have a #for-loop in my template like this:

    #foreach ($column in $column-detail-data)

    "${column.getChild("header").Text}",

    #end

    and I want to now if I'm on the end of the array $column,

    because of the comma at the end of the command.

    If there is no more elements, I don't want to set comma any more.

    Can you give me some advice please?

    Thanks for reply.

    Vitali

    IPS Software GmbH
    Isaac-Fulda-Allee 9
    55124 Mainz
    tel: +49.6131.37577.0
    fax: +49.6131.37577.55
    -
    Niederlassung Munchen:
    Grafinger Str. 2
    81671 Munchen
    tel.: +49.89.18926780
    fax.: +49.89.18926808
    -
    url: http://www.ips-software.de

    Diese e-Mail enthaelt vertrauliche und/oder rechtlich geschuetzte
    Informationen. Wenn Sie nicht der richtige Adressat sind oder diese
    e-Mail irrtuemlich erhalten haben informieren Sie bitte sofort den
    Absender und vernichten Sie diese e-Mail. Das unerlaubte Kopieren
    sowie die unbefugte Weitergabe dieser e-Mail ist nicht gestattet.
    -
    This e-mail contains confidential and/or proprietary information.
    If you are not the intended recipient or if you received the e-Mail
    by mistake we ask you to notify the sender immediately and destroy
    this e-Mail. The unauthorized reproduction or distribution of this
    e-Mail is prohibited.

    To unsubscribe, e-mail: velocity-user-unsubscribe (AT) jakarta (DOT) apache.org
    For additional commands, e-mail: velocity-user-help (AT) jakarta (DOT) apache.org

Re: How to see if there is the end of the array


max 4000 letters.
Your nickname that display:
In order to stop the spam: 2 + 1 =
QUESTION ON "Java"

EMSDN.COM