Windows Vista Forums

Concatenate text string and text in variable with no space between

  1. #1


    Minniti Sergio Guest

    Concatenate text string and text in variable with no space between

    Hi,
    From my powershell script I would like output a text string concatenates
    with some text contained in a $variable with no space before and after the
    $variable.
    Example:
    The email address of Rossi Mario (Acme) is mario.rossi@xxxxxx
    In my powershell script I have witten:
    write-host -foregroundcolor green "The email address of" $DisplayName
    "("$firm") is" $PrimarySmtpAddress
    but the output is
    The email address of Rossi Mario ( Acme) is mario.rossi@xxxxxx
    I don't want the space between ( and Acme.
    How can I do?
    I have written some text lines like:
    $text1 = "The email address of"
    $text2 = "("
    $text3 = ")"
    $text4 = "is"
    #write-host -foregroundcolor green $text1 $DisplayName $text2$firm$text3
    $text4 $PrimarySmtpAddress
    but I don't think that it is correct.
    Have you any idea? I'll wait your reply, thanks!

      My System SpecsSystem Spec

  2. #2


    Vadims Podans [MVP] Guest

    Re: Concatenate text string and text in variable with no space between

    just put all string in double quotes, without separating each part in
    quotes:
    write-host -foregroundcolor green "The email address of $DisplayName ($firm)
    is $PrimarySmtpAddress"
    --
    WBR, Vadims Podans
    MVP: PowerShell
    PowerShell blog - www.sysadmins.lv

    "Minniti Sergio" <MinnitiSergio@xxxxxx> rakstīja ziņojumā
    "news:B98019B7-827E-4B63-B439-F4350053F44E@xxxxxx"...

    > Hi,
    > From my powershell script I would like output a text string concatenates
    > with some text contained in a $variable with no space before and after
    > the
    > $variable.
    > Example:
    > The email address of Rossi Mario (Acme) is mario.rossi@xxxxxx
    > In my powershell script I have witten:
    > write-host -foregroundcolor green "The email address of" $DisplayName
    > "("$firm") is" $PrimarySmtpAddress
    > but the output is
    > The email address of Rossi Mario ( Acme) is mario.rossi@xxxxxx
    > I don't want the space between ( and Acme.
    > How can I do?
    > I have written some text lines like:
    > $text1 = "The email address of"
    > $text2 = "("
    > $text3 = ")"
    > $text4 = "is"
    > #write-host -foregroundcolor green $text1 $DisplayName $text2$firm$text3
    > $text4 $PrimarySmtpAddress
    > but I don't think that it is correct.
    > Have you any idea? I'll wait your reply, thanks!

      My System SpecsSystem Spec

  3. #3


    tojo2000 Guest

    Re: Concatenate text string and text in variable with no spacebetween

    On May 4, 8:47*am, "Vadims Podans [MVP]" <vpodans> wrote:

    > just put all string in double quotes, without separating each part in
    > quotes:
    > write-host -foregroundcolor green "The email address of $DisplayName ($firm)
    > is $PrimarySmtpAddress"
    > --
    > WBR, Vadims Podans
    > MVP: PowerShell
    > PowerShell blog -www.sysadmins.lv
    >
    > "Minniti Sergio" <MinnitiSer...@xxxxxx> rakstīja ziņojumā
    > "news:B98019B7-827E-4B63-B439-F4350053F44E@xxxxxx"...
    >
    >
    >

    > > Hi,
    > > From my powershell script I would like output a text string concatenates
    > > with some text contained in a *$variable with no space before and after
    > > the
    > > $variable.
    > > Example:
    > > The email address of Rossi Mario (Acme) is mario.ro...@xxxxxx
    > > In my powershell script I have witten:
    > > write-host -foregroundcolor green "The email address of" $DisplayName
    > > "("$firm") is" $PrimarySmtpAddress
    > > but the output is
    > > The email address of Rossi Mario ( Acme) is mario.ro...@xxxxxx
    > > I don't *want the space between ( and Acme.
    > > How can I do?
    > > I have written some text lines like:
    > > $text1 = "The email address of"
    > > $text2 = "("
    > > $text3 = ")"
    > > $text4 = "is"
    > > #write-host -foregroundcolor green $text1 $DisplayName $text2$firm$text3
    > > $text4 $PrimarySmtpAddress
    > > but I don't think that it is correct.
    > > Have you any idea? I'll wait your reply, thanks!
    Some other options:

    ($text1 + $DisplayName + ' ' + $text2 + $firm + $text3)

    [string]::join('', ($text1, ' ', $DisplayName, $text2, $firm, $text3))

    'The email address of {0}({1})' -f $DisplayName, $firm





      My System SpecsSystem Spec

  4. #4


    Vadims Podans [MVP] Guest

    Re: Concatenate text string and text in variable with no space between

    With PowerShell V2 you can use -join operator:
    $text1,' ', $DisplayName,' ', $text2, $firm, $text3 -join ""
    --
    WBR, Vadims Podans
    MVP: PowerShell
    PowerShell blog - www.sysadmins.lv

    "tojo2000" <tojo2000@xxxxxx> rakstīja ziņojumā
    "news:4ffef55d-e254-4cf5-ac15-9bbdc8fdce6c@xxxxxx"...

    > On May 4, 8:47 am, "Vadims Podans [MVP]" <vpodans> wrote:

    >> just put all string in double quotes, without separating each part in
    >> quotes:
    >> write-host -foregroundcolor green "The email address of $DisplayName
    >> ($firm)
    >> is $PrimarySmtpAddress"
    >> --
    >> WBR, Vadims Podans
    >> MVP: PowerShell
    >> PowerShell blog -www.sysadmins.lv
    >>
    >> "Minniti Sergio" <MinnitiSer...@xxxxxx> rakstīja
    >> ziņojumā
    >> "news:B98019B7-827E-4B63-B439-F4350053F44E@xxxxxx"...
    >>
    >>
    >>

    >> > Hi,
    >> > From my powershell script I would like output a text string
    >> > concatenates
    >> > with some text contained in a $variable with no space before and after
    >> > the
    >> > $variable.
    >> > Example:
    >> > The email address of Rossi Mario (Acme) is mario.ro...@xxxxxx
    >> > In my powershell script I have witten:
    >> > write-host -foregroundcolor green "The email address of" $DisplayName
    >> > "("$firm") is" $PrimarySmtpAddress
    >> > but the output is
    >> > The email address of Rossi Mario ( Acme) is mario.ro...@xxxxxx
    >> > I don't want the space between ( and Acme.
    >> > How can I do?
    >> > I have written some text lines like:
    >> > $text1 = "The email address of"
    >> > $text2 = "("
    >> > $text3 = ")"
    >> > $text4 = "is"
    >> > #write-host -foregroundcolor green $text1 $DisplayName
    >> > $text2$firm$text3
    >> > $text4 $PrimarySmtpAddress
    >> > but I don't think that it is correct.
    >> > Have you any idea? I'll wait your reply, thanks!
    >
    > Some other options:
    >
    > ($text1 + $DisplayName + ' ' + $text2 + $firm + $text3)
    >
    > [string]::join('', ($text1, ' ', $DisplayName, $text2, $firm, $text3))
    >
    > 'The email address of {0}({1})' -f $DisplayName, $firm
    >
    >
    >
    >

      My System SpecsSystem Spec

  5. #5


    tojo2000 Guest

    Re: Concatenate text string and text in variable with no spacebetween

    On May 5, 11:14*pm, "Vadims Podans [MVP]" <vpodans> wrote:

    > With PowerShell V2 you can use -join operator:
    > *$text1,' ', $DisplayName,' ', $text2, $firm, $text3 -join ""
    > --
    > WBR, Vadims Podans
    > MVP: PowerShell
    > PowerShell blog -www.sysadmins.lv
    >
    > "tojo2000" <tojo2...@xxxxxx> rakstīja ziņojumā
    > "news:4ffef55d-e254-4cf5-ac15-9bbdc8fdce6c@xxxxxx"....
    >
    >
    >

    > > On May 4, 8:47 am, "Vadims Podans [MVP]" <vpodans> wrote:

    > >> just put all string in double quotes, without separating each part in
    > >> quotes:
    > >> write-host -foregroundcolor green "The email address of $DisplayName
    > >> ($firm)
    > >> is $PrimarySmtpAddress"
    > >> --
    > >> WBR, Vadims Podans
    > >> MVP: PowerShell
    > >> PowerShell blog -www.sysadmins.lv
    >

    > >> "Minniti Sergio" <MinnitiSer...@xxxxxx> rakstīja
    > >> ziņojumā
    > >> "news:B98019B7-827E-4B63-B439-F4350053F44E@xxxxxx"...
    >

    > >> > Hi,
    > >> > From my powershell script I would like output a text string
    > >> > concatenates
    > >> > with some text contained in a *$variable with no space before and after
    > >> > the
    > >> > $variable.
    > >> > Example:
    > >> > The email address of Rossi Mario (Acme) is mario.ro...@xxxxxx
    > >> > In my powershell script I have witten:
    > >> > write-host -foregroundcolor green "The email address of" $DisplayName
    > >> > "("$firm") is" $PrimarySmtpAddress
    > >> > but the output is
    > >> > The email address of Rossi Mario ( Acme) is mario.ro...@xxxxxx
    > >> > I don't *want the space between ( and Acme.
    > >> > How can I do?
    > >> > I have written some text lines like:
    > >> > $text1 = "The email address of"
    > >> > $text2 = "("
    > >> > $text3 = ")"
    > >> > $text4 = "is"
    > >> > #write-host -foregroundcolor green $text1 $DisplayName
    > >> > $text2$firm$text3
    > >> > $text4 $PrimarySmtpAddress
    > >> > but I don't think that it is correct.
    > >> > Have you any idea? I'll wait your reply, thanks!
    >

    > > Some other options:
    >

    > > ($text1 + $DisplayName + ' ' + $text2 + $firm + $text3)
    >

    > > [string]::join('', ($text1, ' ', $DisplayName, $text2, $firm, $text3))
    >

    > > 'The email address of {0}({1})' -f $DisplayName, $firm
    Thanks, I keep forgetting about that. It seems strange to me that join
    () is such an afterthought in .NET, with strings having a split()
    method but not a join() by default.

      My System SpecsSystem Spec

Concatenate text string and text in variable with no space between

Similar Threads
Thread Forum
manipulating text inside a variable
hi, I was wondering if someone know a way of doing the following. I have text saved in a file, this file is generated by another team. I have...
PowerShell
Concatenate text string and text in variable with no space between
Hi, From my powershell script I would like output a text string concatenates with some text contained in a $variable with no space before and...
VB Script
How to concatenate a literal string and a variable value?
Assume I want to concatenate a literal text value and a variable value for a function parameter then the following does NOT work: ...
VB Script
Creating a Text string
Hi, I am trying to put together a Text sting using some variables. Looks good so far; foreach ($item in $filelist) { $aItems =...
PowerShell
Refresh on Reading more than one variable from a Text file
Hi, I know this is an old one, but I can't recall how to do it. I want to read a text file and pick up two variables for my script. The first...
VB Script
how to get text string from description?
Just started to play with powershll and is using CTP2. $a = get-help write-error $b = $a.description If I typed $b, I get r information...
PowerShell
How to Concatenate text files?
Hello PowerShellers, How would I concatenate several text files into a single file using PowerShell cmdlets? Using my UNIX powers, I can use...
PowerShell