how to concat two strings into one?

Discussion in 'Perl Misc' started by mozilla.bugzilla@gmail.com, Jul 9, 2005.

  1. Guest

    hi, greetings,

    I am a newer for PERL. I want to concat two strings into one string,
    like this,

    $stringA='This is ';
    $stringB='A concat example!';

    I want to $stingC to be this: $stringC="This is A concat example!";

    I searched the help, but did not find the right function, Can you guys
    help me figure this out?

    Thanks

    bugzilla
     
    , Jul 9, 2005
    #1
    1. Advertising

  2. writes:

    > I am a newer for PERL.


    BTW, it's Perl, not PERL.

    > I want to concat two strings into one string,
    > like this,
    >
    > $stringA='This is ';
    > $stringB='A concat example!';
    >
    > I want to $stingC to be this: $stringC="This is A concat example!";
    >
    > I searched the help, but did not find the right function, Can you guys
    > help me figure this out?


    You searched the wrong help - it's an operator, not a function.

    The dot . operator is used for string concatenation, like this:

    my $stringC = $stringA . $stringB;

    Have a look at "perldoc perlop" for details.

    sherm--

    --
    Cocoa programming in Perl: http://camelbones.sourceforge.net
    Hire me! My resume: http://www.dot-app.org
     
    Sherm Pendley, Jul 9, 2005
    #2
    1. Advertising

  3. Guest

    Thank you so much,sherm! It works.


    bugzilla
     
    , Jul 9, 2005
    #3
  4. wrote:
    > I am a newer for PERL. I want to concat two strings into one string,
    > like this,
    >
    > $stringA='This is ';
    > $stringB='A concat example!';
    >
    > I want to $stingC to be this: $stringC="This is A concat example!";


    Some ways to do it:
    $stringC = $stringA . $stringB;
    $stringC = "$stringA$stringB";
    $stringC = join('', ($stringA, $stringB));

    I'm sure there are more.

    jue
     
    Jürgen Exner, Jul 9, 2005
    #4
  5. Brandon Guest

    hi,

    It woudl be something like:

    print $stringA . $stringB;

    You use the "." operator.

    Brandon

    <> wrote in message
    news:...
    > hi, greetings,
    >
    > I am a newer for PERL. I want to concat two strings into one string,
    > like this,
    >
    > $stringA='This is ';
    > $stringB='A concat example!';
    >
    > I want to $stingC to be this: $stringC="This is A concat example!";
    >
    > I searched the help, but did not find the right function, Can you guys
    > help me figure this out?
    >
    > Thanks
    >
    > bugzilla
    >
     
    Brandon, Jul 9, 2005
    #5
  6. Joe Smith Guest

    wrote:
    > I am a newer for PERL. I want to concat two strings into one string...
    > I searched the help, but did not find the right function...


    You should not be searching the help files for this.
    You should be reading an "Introduction to Perl" tutorial.

    This question and others imply that haven't been introduced
    to the basics of Perl. What are you using as a reference?
    -Joe
     
    Joe Smith, Jul 10, 2005
    #6
  7. Anno Siegel Guest

    Jürgen Exner <> wrote in comp.lang.perl.misc:
    > wrote:
    > > I am a newer for PERL. I want to concat two strings into one string,
    > > like this,
    > >
    > > $stringA='This is ';
    > > $stringB='A concat example!';
    > >
    > > I want to $stingC to be this: $stringC="This is A concat example!";

    >
    > Some ways to do it:
    > $stringC = $stringA . $stringB;
    > $stringC = "$stringA$stringB";
    > $stringC = join('', ($stringA, $stringB));
    >
    > I'm sure there are more.


    $stringC = '';
    substr( $stringC, length $stringC, 0, $_) for $stringA, $stringB;

    Anno
    --
    If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers.
     
    Anno Siegel, Jul 11, 2005
    #7
    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. ctb
    Replies:
    2
    Views:
    2,591
    S. Justin Gengo
    Jul 18, 2003
  2. Timo Nentwig

    EL: concat strings

    Timo Nentwig, May 8, 2004, in forum: Java
    Replies:
    4
    Views:
    18,803
    Murray
    May 8, 2004
  3. news.frontiernet.net
    Replies:
    6
    Views:
    1,168
    news.frontiernet.net
    Apr 16, 2004
  4. Ben

    Strings, Strings and Damned Strings

    Ben, Jun 22, 2006, in forum: C Programming
    Replies:
    14
    Views:
    810
    Malcolm
    Jun 24, 2006
  5. Tobias Müller
    Replies:
    0
    Views:
    128
    Tobias Müller
    Dec 9, 2013
Loading...

Share This Page