[FR/EN] string conversion.

Discussion in 'Perl Misc' started by Alextophi, Sep 23, 2005.

  1. Alextophi

    Alextophi Guest

    FR
    -------------------------------------------------------------------------
    Bonjour, voici mon problème :

    - C'est une conversion de jour de semaine, du français vers l'anglais
    et le '-I' n'est pas utile.

    - '$my_str_in' peut contenir un ou plusieur mot; ' Lu-I Ma-I Me-I Je-I
    Ve-I Sa-I Di-I Tlj-I Lu-F Ma-F Me-F Je-F Ve-F Sa-F Di-F Tlj-F '


    - Je dois convertir la chaine, '$my_str_in' = "Lu-I Ma-I Me-I"; en
    chaine : '$my_str_out' = "Mon-Tue-Wed";


    Comment faire ?


    merci, christophe



    EN
    ------------------------------------------------------------------------

    hello, here my problem:

    - It is a conversion of day of week, from French towards English and it
    '-I' is not useful.

    - '$my_str_in' can contain one or plusior word; ' Lu-I Ma-I Me-I Je-I
    Ve-I Sa-I Di-I Tlj-I Lu-F Ma-F Me-F Je-F Ve-F Sa-F Di-F Tlj-F '

    - I must convert the chains, '$my_str_in' = "Lu-I Ma-I Me-I"; en chaine
    : '$my_str_out' = "Mon-Tue-Wed";

    How to make this fonction ?

    thank you, Christophe







    for ($i=0;$i<100;$i++) {print "I am really null";}
    *------------------------------------------------*
     
    Alextophi, Sep 23, 2005
    #1
    1. Advertising

  2. Alextophi wrote:
    > FR
    > -------------------------------------------------------------------------
    > Bonjour, voici mon problème :
    >
    > - C'est une conversion de jour de semaine, du français vers l'anglais
    > et le '-I' n'est pas utile.
    >
    > - '$my_str_in' peut contenir un ou plusieur mot; ' Lu-I Ma-I Me-I Je-I
    > Ve-I Sa-I Di-I Tlj-I Lu-F Ma-F Me-F Je-F Ve-F Sa-F Di-F Tlj-F '
    >
    >
    > - Je dois convertir la chaine, '$my_str_in' = "Lu-I Ma-I Me-I"; en
    > chaine : '$my_str_out' = "Mon-Tue-Wed";
    >
    >
    > Comment faire ?
    >
    >
    > merci, christophe
    >
    >
    >
    > EN
    > ------------------------------------------------------------------------
    >
    > hello, here my problem:
    >
    > - It is a conversion of day of week, from French towards English and it
    > '-I' is not useful.
    >
    > - '$my_str_in' can contain one or plusior word; ' Lu-I Ma-I Me-I Je-I
    > Ve-I Sa-I Di-I Tlj-I Lu-F Ma-F Me-F Je-F Ve-F Sa-F Di-F Tlj-F '
    >
    > - I must convert the chains, '$my_str_in' = "Lu-I Ma-I Me-I"; en chaine
    > : '$my_str_out' = "Mon-Tue-Wed";
    >
    > How to make this fonction ?


    Just write it!

    If it doesn't work as expected, come here again and show us what you've
    tried.

    --
    Josef Möllers (Pinguinpfleger bei FSC)
    If failure had no penalty success would not be a prize
    -- T. Pratchett
     
    Josef Moellers, Sep 23, 2005
    #2
    1. Advertising

  3. Alextophi

    Alextophi Guest

    Re: string conversion.

    ok I understand, here the code:

    #Call function
    &funct_conv("Lu-I Ma-I Me-I");
    print "string_out"; # see "Mon-Tue-Wed"



    ------------------------------------------------------
    sub funct_conv {
    my @SCHED = split(" ", $_[0]);


    my %day = ('Lu-I' => "Mon",
    'Ma-I' => "Tue",
    'Me-I' => "Wed",
    'Je-I' => "Thu",
    'Ve-I' => "Fri",
    'Sa-I' => "Sat",
    'Di-I' => "Sun",
    'Lu-F' => "Mon",
    'Ma-F' => "Tue",
    'Me-F' => "Wed",
    'Je-F' => "Thu",
    'Ve-F' => "Fri",
    'Sa-F' => "Sat",
    'Di-F' => "Sun",
    'Tlj-' => "Mon-Tue-Wed-Thu-Fri-Sat-Sun"
    );

    foreach my $SCHED(@SCHED){
    my $DayEN = $day{substr($SCHED,0,4)};


    $string_out = $DayEN # how to make a list of result?

    }

    return ($string_out);

    } # end
    ------------------------------------------------------

    tank's
     
    Alextophi, Sep 23, 2005
    #3
  4. Alextophi

    Babacio Guest

    Re: string conversion.

    "Alextophi" <> writes:

    Try that :


    print funct_conv("Lu-I Ma-I Me-I");

    sub funct_conv {
    my @SCHED = split(" ", $_[0]);

    my %day = ('Lu-I' => "Mon", 'Ma-I' => "Tue", 'Me-I' => "Wed",
    'Je-I' => "Thu", 'Ve-I' => "Fri", 'Sa-I' => "Sat",
    'Di-I' => "Sun", 'Lu-F' => "Mon", 'Ma-F' => "Tue",
    'Me-F' => "Wed", 'Je-F' => "Thu", 'Ve-F' => "Fri",
    'Sa-F' => "Sat", 'Di-F' => "Sun",
    'Tlj-' => "Mon-Tue-Wed-Thu-Fri-Sat-Sun"
    );

    my @result;

    foreach my $SCHED(@SCHED){
    my $DayEN = $day{substr($SCHED,0,4)};
    push @result, $DayEN;
    }
    return join("-",@result);
    }


    --
    Bé erre hue ixe eu elle, Bruxelles.
     
    Babacio, Sep 23, 2005
    #4
  5. Re: string conversion.

    Alextophi wrote:
    > ok I understand, here the code:
    >
    > #Call function
    > &funct_conv("Lu-I Ma-I Me-I");
    > print "string_out"; # see "Mon-Tue-Wed"
    >
    >
    >
    > ------------------------------------------------------
    > sub funct_conv {
    > my @SCHED = split(" ", $_[0]);
    >
    >
    > my %day = ('Lu-I' => "Mon",
    > 'Ma-I' => "Tue",
    > 'Me-I' => "Wed",
    > 'Je-I' => "Thu",
    > 'Ve-I' => "Fri",
    > 'Sa-I' => "Sat",
    > 'Di-I' => "Sun",
    > 'Lu-F' => "Mon",
    > 'Ma-F' => "Tue",
    > 'Me-F' => "Wed",
    > 'Je-F' => "Thu",
    > 'Ve-F' => "Fri",
    > 'Sa-F' => "Sat",
    > 'Di-F' => "Sun",
    > 'Tlj-' => "Mon-Tue-Wed-Thu-Fri-Sat-Sun"
    > );
    >
    > foreach my $SCHED(@SCHED){
    > my $DayEN = $day{substr($SCHED,0,4)};
    >
    >
    > $string_out = $DayEN # how to make a list of result?
    >
    > }
    >
    > return ($string_out);
    >
    > } # end
    > ------------------------------------------------------
    >
    > tank's
    >


    Ok, no need to send in the Panzers B-{)

    One way to do it would be to store the intermediate result in an array,
    then join the array members to return them:

    my @result;
    foreach my $SCHED(@SCHED){
    my $DayEN = $day{substr($SCHED,0,4)};


    push @result, $DayEN;

    }

    return join(" ", @result);
    } # end

    Josef

    --
    Josef Möllers (Pinguinpfleger bei FSC)
    If failure had no penalty success would not be a prize
    -- T. Pratchett
     
    Josef Moellers, Sep 23, 2005
    #5
  6. Alextophi

    Babacio Guest

    Re: string conversion.

    Josef Moellers.

    > my @result;
    > foreach my $SCHED(@SCHED){
    > my $DayEN = $day{substr($SCHED,0,4)};
    >
    >
    > push @result, $DayEN;
    >
    > }
    >
    > return join(" ", @result);
    > } # end


    Darn, were you first to reply? And even the same variable name!
    Gosh, this is supranatural, I'll find smoe garlic.

    --
    Bé erre hue ixe eu elle, Bruxelles.
     
    Babacio, Sep 23, 2005
    #6
  7. Re: string conversion.

    Alextophi wrote:
    > ok I understand,


    What do you understand?

    > here the code:


    See proposed changes below.

    > #Call function
    > &funct_conv("Lu-I Ma-I Me-I");
    > print "string_out"; # see "Mon-Tue-Wed"


    Replace that with

    print funct_conf("Lu-I Ma-I Me-I");

    > sub funct_conv {
    > my @SCHED = split(" ", $_[0]);


    Declare an array where days are temporarily stored in English:

    my @daysEN;

    > my %day = ('Lu-I' => "Mon",
    > 'Ma-I' => "Tue",
    > 'Me-I' => "Wed",
    > 'Je-I' => "Thu",
    > 'Ve-I' => "Fri",
    > 'Sa-I' => "Sat",
    > 'Di-I' => "Sun",
    > 'Lu-F' => "Mon",
    > 'Ma-F' => "Tue",
    > 'Me-F' => "Wed",
    > 'Je-F' => "Thu",
    > 'Ve-F' => "Fri",
    > 'Sa-F' => "Sat",
    > 'Di-F' => "Sun",
    > 'Tlj-' => "Mon-Tue-Wed-Thu-Fri-Sat-Sun"
    > );
    >
    > foreach my $SCHED(@SCHED){
    > my $DayEN = $day{substr($SCHED,0,4)};
    >
    >
    > $string_out = $DayEN # how to make a list of result?


    push @daysEN, $DayEN;

    > }
    >
    > return ($string_out);


    return join '-', @daysEN;

    > } # end


    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Sep 23, 2005
    #7
  8. Alextophi

    Alextophi Guest

    Re: string conversion.

    Thank you with all,

    - that functions!!

    there is just a trick : return join("-", @result);

    the result does not have it '-' between the values! !

    thank you very much, Christophe
     
    Alextophi, Sep 23, 2005
    #8
  9. Alextophi

    Babacio Guest

    Re: string conversion.

    "Alextophi".

    > there is just a trick : return join("-", @result);
    >
    > the result does not have it '-' between the values! !


    I don't understand what you mean. I think I am the one you're talking
    to, because I wrote this join with a '-' ; (I sure wrote "-", but '-'
    is better). If there is stull something wrong, feel free to write to
    me directly (in french ;)

    --
    Bé erre hue ixe eu elle, Bruxelles.
     
    Babacio, Sep 23, 2005
    #9
  10. Alextophi

    Alextophi Guest

    Re: string conversion.

    ok

    en fait le "-" (trait-d'union) n'apparait pas dans la chaine @result

    ex: "Mon Tue Wed Thu Fri"


    ch.
     
    Alextophi, Sep 23, 2005
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stefan Duenser

    Conversion: String to std_ulogic_vector

    Stefan Duenser, Dec 9, 2004, in forum: VHDL
    Replies:
    2
    Views:
    668
  2. =?ISO-8859-1?Q?Hel=E9ne?=

    Problem with string and base64binary conversion

    =?ISO-8859-1?Q?Hel=E9ne?=, Jul 21, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    2,919
  3. James Tillery
    Replies:
    2
    Views:
    528
    James Tillery
    Oct 25, 2004
  4. Alexander Eisenhuth
    Replies:
    5
    Views:
    561
    Bob Gailer
    Jul 25, 2003
  5. , India
    Replies:
    2
    Views:
    506
    Fraser Ross
    Sep 15, 2009
Loading...

Share This Page