Difference between revisions of "Concatenate two strings"

From CodeCodex

(Delphi)
(X86 Assembly)
 
(17 intermediate revisions by 13 users not shown)
Line 1: Line 1:
 
{{Infobox See Also String}}
 
{{Infobox See Also String}}
 
==X86 Assembly==
 
==X86 Assembly==
<HIGHLIGHTSYNTAX language="asm_x86">
+
DATA SEGMENT
mov ecx, -1
+
        STR1 DB "ENTER FIRST STRING HERE ->$"
xor al, al
+
        STR2 DB "ENTER SECOND STRING HERE ->$"
lea edi, destination
+
        STR3 DB "CONCATED STRING :->$"
repnz scasb
+
        STR11 DB "FIRST STRING : ->$"
lea esi, source
+
        STR22 DB "SECOND STRING: ->$"
  
loop:
+
        INSTR1 DB 20 DUP("$")
lodsb
+
        INSTR2 DB 20 DUP("$")
stosb
+
        N DB ?
test al, al
+
        N1 DB ?
jnz loop
+
        NEWLINE DB 10,13,"$"
</HIGHLIGHTSYNTAX>
+
 
 +
DATA ENDS
 +
 
 +
CODE SEGMENT
 +
 
 +
        ASSUME DS:DATA,CS:CODE
 +
START:
 +
 
 +
        MOV AX,DATA
 +
        MOV DS,AX
 +
 
 +
        LEA SI,INSTR1
 +
        LEA DI,INSTR2
 +
 
 +
;GET STRING
 +
        MOV AH,09H
 +
        LEA DX,STR1
 +
        INT 21H
 +
 
 +
        MOV AH,0AH
 +
        MOV DX,SI
 +
        INT 21H
 +
 
 +
 
 +
        MOV AH,09H
 +
        LEA DX,NEWLINE
 +
        INT 21H
 +
 
 +
        MOV AH,09H
 +
        LEA DX,STR2
 +
        INT 21H
 +
 
 +
        MOV AH,0AH
 +
        MOV DX,DI
 +
        INT 21H
 +
 
 +
 
 +
        MOV AH,09H
 +
        LEA DX,NEWLINE
 +
        INT 21H
 +
 
 +
 
 +
;PRINT THE STRING
 +
 
 +
        MOV AH,09H
 +
        LEA DX,STR11
 +
        INT 21H
 +
 
 +
        MOV AH,09H
 +
        LEA DX,INSTR1+2
 +
        INT 21H
 +
 
 +
        MOV AH,09H
 +
        LEA DX,NEWLINE
 +
        INT 21H
 +
 
 +
        MOV AH,09H
 +
        LEA DX,STR22                   
 +
        INT 21H
 +
 
 +
        MOV AH,09H
 +
        LEA DX,INSTR2+2
 +
        INT 21H
 +
 
 +
        MOV AH,09H
 +
        LEA DX,NEWLINE
 +
        INT 21H
 +
 
 +
;CONCATINATION OF THE STRING
 +
 
 +
        LEA SI,INSTR1
 +
        LEA DI,INSTR2
 +
        MOV CX,00
 +
 
 +
        INC SI
 +
 
 +
    L1:INC SI
 +
        CMP BYTE PTR[SI],"$"
 +
        JNE L1
 +
 
 +
        ADD DI,2
 +
        MOV BX,0
 +
      L2:
 +
     
 +
        MOV BL,BYTE PTR[DI]
 +
        MOV BYTE PTR[SI],BL
 +
       
 +
        INC SI
 +
        INC DI
 +
 
 +
        CMP BYTE PTR[DI],"$"
 +
 
 +
        JNE L2
 +
 
 +
    L8:DEC SI
 +
        CMP SI,2
 +
        JNE L8
 +
 
 +
       
 +
        MOV AH,09H
 +
        LEA DX,NEWLINE
 +
        INT 21H
 +
 
 +
        MOV AH,09H
 +
        LEA DX,STR3
 +
        INT 21H
 +
 
 +
        MOV AH,09H
 +
        LEA DX,NEWLINE
 +
        INT 21H
 +
 
 +
 
 +
 
 +
    L6:
 +
        MOV BL,BYTE PTR[SI]
 +
 
 +
        MOV AH,02H
 +
        MOV DL,BL
 +
        INT 21H
 +
 
 +
        INC SI
 +
        CMP BYTE PTR[SI],"$"
 +
        JNE L6
 +
 
 +
;      MOV AH,09H
 +
;      LEA DX,INSTR1+2
 +
  ;      INT 21
 +
 
 +
        MOV AH,4CH
 +
        INT 21H
 +
 
 +
 
 +
CODE ENDS
 +
END START
  
 
==Ada==
 
==Ada==
<HIGHLIGHTSYNTAX>
+
<pre>
 
Foo : Unbounded_String := Foo & Bar;
 
Foo : Unbounded_String := Foo & Bar;
</HIGHLIGHTSYNTAX>
+
</pre>
  
 
==AppleScript==
 
==AppleScript==
<HIGHLIGHTSYNTAX>
+
<pre>
 
  set newString to aString & anotherString
 
  set newString to aString & anotherString
</HIGHLIGHTSYNTAX>
+
</pre>
  
 
==ASP==
 
==ASP==
<HIGHLIGHTSYNTAX language="aspvb">
+
<pre>
 
Dim sSomeText
 
Dim sSomeText
 
sSomeText = "This is some text" & " and this is some more text."
 
sSomeText = "This is some text" & " and this is some more text."
</HIGHLIGHTSYNTAX>
+
</pre>
  
 
==BASIC==
 
==BASIC==
<HIGHLIGHTSYNTAX>
+
<pre>
 
foobar = foo + bar
 
foobar = foo + bar
</HIGHLIGHTSYNTAX>
+
</pre>
  
 
==C==
 
==C==
<HIGHLIGHTSYNTAX language="c">
+
<pre class="c">
 
strcat(destination, source);
 
strcat(destination, source);
</HIGHLIGHTSYNTAX>
+
</pre>
 
The string at "destination" is modified. The programmer must ensure that "destination" points to a block of memory large enough to hold the length of the concatenated string, plus the null terminator; otherwise it will overflow the buffer. You need to <code>#include <string.h></code> for it to work.
 
The string at "destination" is modified. The programmer must ensure that "destination" points to a block of memory large enough to hold the length of the concatenated string, plus the null terminator; otherwise it will overflow the buffer. You need to <code>#include <string.h></code> for it to work.
  
 
==C++==
 
==C++==
<HIGHLIGHTSYNTAX language="cpp">
+
<pre class="cpp">
 
foobar = foo + bar;
 
foobar = foo + bar;
</HIGHLIGHTSYNTAX>
+
foo += bar; //modifies foo
assuming that "foo" and "bar" are std::string objects.
+
foo.append(bar);
 
+
</pre>
==COBOL==
+
//assuming that "foo" and "bar" are std::string objects.
STRING Foo, Bar
+
    INTO Foobar
+
END-STRING
+
 
+
Sample "WORKING-STORAGE SECTION."
+
01 Foo PIC X(3) VALUE "Foo".
+
01 Bar PIC X(3) VALUE "Bar".
+
01 Foobar PIC X(6).
+
  
 
==Common Lisp==
 
==Common Lisp==
<HIGHLIGHTSYNTAX language="lisp">
+
<pre>
 
(concatenate 'string a-string another-string)
 
(concatenate 'string a-string another-string)
</HIGHLIGHTSYNTAX>
+
</pre>
  
 
==Objective-C==
 
==Objective-C==
<HIGHLIGHTSYNTAX>
+
<pre>
 
  NSString *foobar = [aStringObject stringByAppendingString:anotherStringObject];
 
  NSString *foobar = [aStringObject stringByAppendingString:anotherStringObject];
</HIGHLIGHTSYNTAX>
+
</pre>
 
alternatively:
 
alternatively:
<HIGHLIGHTSYNTAX>
+
<pre>
 
  NSString *foobar = [NSString stringWithFormat:@"%@%@", aStringObject, anotherStringObject];
 
  NSString *foobar = [NSString stringWithFormat:@"%@%@", aStringObject, anotherStringObject];
</HIGHLIGHTSYNTAX>
+
</pre>
 
+
Another solution:
another way:
+
<pre>
 
+
<HIGHLIGHTSYNTAX>
+
 
  NSMutableString *foobar = [NSMutableString stringWithString:aStringObject];
 
  NSMutableString *foobar = [NSMutableString stringWithString:aStringObject];
 
  [foobar appendString: anotherStringObject];
 
  [foobar appendString: anotherStringObject];
</HIGHLIGHTSYNTAX>
+
</pre>
  
 
==D==
 
==D==
Line 92: Line 215:
  
 
==Delphi==
 
==Delphi==
<HIGHLIGHTSYNTAX>
+
<pre>
 
foobar := 'foo' + 'bar' ;
 
foobar := 'foo' + 'bar' ;
</HIGHLIGHTSYNTAX>
+
</pre>
 +
 
 +
==Erlang==
 +
<pre>
 +
Foobar = "foo" ++ "bar".
 +
</pre>
  
 
==Gibiane==
 
==Gibiane==
<HIGHLIGHTSYNTAX>
+
<pre>
 
foobar = concat: 'foo' string 'bar' ;
 
foobar = concat: 'foo' string 'bar' ;
</HIGHLIGHTSYNTAX>
+
</pre>
 +
 
 +
==Go==
 +
<pre>
 +
foobar := foo + bar
 +
</pre>
  
 
==Groovy==
 
==Groovy==
 
Dynamic variable:
 
Dynamic variable:
<HIGHLIGHTSYNTAX>
+
<pre>
 
foobar = foo + bar
 
foobar = foo + bar
</HIGHLIGHTSYNTAX>
+
</pre>
  
 
Faster way:
 
Faster way:
<HIGHLIGHTSYNTAX>
+
<pre>
 
foobar = "$foo$bar"
 
foobar = "$foo$bar"
</HIGHLIGHTSYNTAX>
+
</pre>
  
 
With static variable:
 
With static variable:
<HIGHLIGHTSYNTAX>
+
<pre>
 
String foobar = "$foo$bar"
 
String foobar = "$foo$bar"
</HIGHLIGHTSYNTAX>
+
</pre>
  
 
==Haskell==
 
==Haskell==
<HIGHLIGHTSYNTAX language="haskell">
+
<pre>
 
foobar = foo ++ bar
 
foobar = foo ++ bar
</HIGHLIGHTSYNTAX>
+
</pre>
  
 
==Java==
 
==Java==
<HIGHLIGHTSYNTAX language="java122">
+
<pre class="java">
 
foobar = foo + bar;
 
foobar = foo + bar;
</HIGHLIGHTSYNTAX>
+
</pre>
  
 
Slightly faster way:
 
Slightly faster way:
<HIGHLIGHTSYNTAX language="java122">
+
<pre class="java">
 
foobar = new StringBuilder(foo).append(bar).toString();
 
foobar = new StringBuilder(foo).append(bar).toString();
</HIGHLIGHTSYNTAX>
+
</pre>
  
 
Slower, but thread-safe:
 
Slower, but thread-safe:
<HIGHLIGHTSYNTAX language="java122">
+
<pre class="java">
 
foobar = new StringBuffer(foo).append(bar).toString();
 
foobar = new StringBuffer(foo).append(bar).toString();
</HIGHLIGHTSYNTAX>
+
</pre>
  
 
==Javascript==
 
==Javascript==
<HIGHLIGHTSYNTAX language="javascript">
+
<pre class="javascript">
 
var foobar = foo + bar;
 
var foobar = foo + bar;
 
var foobar = [foo,bar].join('');
 
var foobar = [foo,bar].join('');
</HIGHLIGHTSYNTAX>
+
</pre>
  
==LUA==
+
==Lua==
<HIGHLIGHTSYNTAX>
+
<pre>
 
foobar = foo .. bar
 
foobar = foo .. bar
</HIGHLIGHTSYNTAX>
+
</pre>
  
 
==Matlab==
 
==Matlab==
<HIGHLIGHTSYNTAX language="matlab5">
+
<pre>
 
foobar = ['foo' 'bar'];
 
foobar = ['foo' 'bar'];
</HIGHLIGHTSYNTAX>
+
</pre>
  
 
Alternatively:
 
Alternatively:
<HIGHLIGHTSYNTAX language="matlab5">
+
<pre>
foobar = strcat(fgsfds, dsfargeg);
+
foobar = strcat(foo, bar);
</HIGHLIGHTSYNTAX>
+
</pre>
 +
 
 +
Note: The second method trims spaces, while the first method does not.
  
 
==Modula-3==
 
==Modula-3==
 
Sample variable declaration:
 
Sample variable declaration:
<HIGHLIGHTSYNTAX>
+
<pre>
 
VAR foo: TEXT := "Foo";
 
VAR foo: TEXT := "Foo";
 
VAR bar: TEXT := "Bar";
 
VAR bar: TEXT := "Bar";
 
VAR foobar : TEXT;
 
VAR foobar : TEXT;
</HIGHLIGHTSYNTAX>
+
</pre>
 
Sample code:
 
Sample code:
<HIGHLIGHTSYNTAX>
+
<pre>
 
foobar := foo & bar;
 
foobar := foo & bar;
</HIGHLIGHTSYNTAX>
+
</pre>
  
 
==OCaml==
 
==OCaml==
<HIGHLIGHTSYNTAX language="ocaml">
+
<pre>
 
let foobar = foo ^ bar
 
let foobar = foo ^ bar
</HIGHLIGHTSYNTAX>
+
</pre>
  
 
==Pascal==
 
==Pascal==
<HIGHLIGHTSYNTAX>
+
<pre>
 
var foobar : String;
 
var foobar : String;
 
foobar := Concat(foo, bar);
 
foobar := Concat(foo, bar);
</HIGHLIGHTSYNTAX>
+
</pre>
  
 
==Perl==
 
==Perl==
<HIGHLIGHTSYNTAX language="perl">
+
<pre>
 
  $foobar = $foo.$bar;  # concatenation
 
  $foobar = $foo.$bar;  # concatenation
 
  $foo  .= $bar;      # assignment concatenation
 
  $foo  .= $bar;      # assignment concatenation
 
  $foobar = "$foo$bar"; # interpolation
 
  $foobar = "$foo$bar"; # interpolation
</HIGHLIGHTSYNTAX>
+
</pre>
  
 
==PHP==
 
==PHP==
<HIGHLIGHTSYNTAX language="php3">
+
<pre class="php">
 
  $foobar = $foo.$bar;
 
  $foobar = $foo.$bar;
 
  $foobar = "$foo$bar";
 
  $foobar = "$foo$bar";
 
  $foo .= $bar;
 
  $foo .= $bar;
</HIGHLIGHTSYNTAX>
+
</pre>
  
 
==PL/SQL==
 
==PL/SQL==
<HIGHLIGHTSYNTAX language="php3">
+
<pre>
 
  foobar := foo || bar;
 
  foobar := foo || bar;
</HIGHLIGHTSYNTAX>
+
</pre>
  
 
==Python==
 
==Python==
<HIGHLIGHTSYNTAX language="python">
+
<pre class="python">
 
foobar = foo + bar
 
foobar = foo + bar
</HIGHLIGHTSYNTAX>
+
</pre>
 
Concatenate N strings:
 
Concatenate N strings:
<HIGHLIGHTSYNTAX language="python">
+
<pre class="python">
 
list_of_strings = ['abc', 'def', 'ghi']
 
list_of_strings = ['abc', 'def', 'ghi']
 
foobar = ''.join(list_of_strings)
 
foobar = ''.join(list_of_strings)
</HIGHLIGHTSYNTAX>
+
</pre>
  
 
Alternatively:
 
Alternatively:
<HIGHLIGHTSYNTAX language="python">
+
<pre class="python">
 
  foobar = '%s, %s' % ('abc', 'def')
 
  foobar = '%s, %s' % ('abc', 'def')
</HIGHLIGHTSYNTAX>
+
</pre>
  
 
==R==
 
==R==
<HIGHLIGHTSYNTAX>
+
<pre>
 
foo = "string1"
 
foo = "string1"
 
bar = "string2"
 
bar = "string2"
 
foobar = paste(foo,bar,sep="")
 
foobar = paste(foo,bar,sep="")
</HIGHLIGHTSYNTAX>
+
</pre>
  
 
==Rexx==
 
==Rexx==
<HIGHLIGHTSYNTAX>
+
<pre>
 
foobar = foo || bar
 
foobar = foo || bar
</HIGHLIGHTSYNTAX>
+
</pre>
  
 
==Ruby==
 
==Ruby==
<HIGHLIGHTSYNTAX>
+
<pre class="ruby">
string = "one " + "two"
+
 
+
# Alternatively:
+
 
one = "one"
 
one = "one"
 
two = "two"
 
two = "two"
string = "#{one} #{two}"
+
string = one + two
 +
 
 +
# Alternatively:
 +
string = "#{one}#{two}"
  
 
# Or even:
 
# Or even:
 
string = [ one, two ].join
 
string = [ one, two ].join
</HIGHLIGHTSYNTAX>
+
</pre>
  
 
==Scala==
 
==Scala==
<HIGHLIGHTSYNTAX>
+
<pre>
 
var foobar: String = foo + bar;
 
var foobar: String = foo + bar;
</HIGHLIGHTSYNTAX>
+
</pre>
  
 
Faster way:
 
Faster way:
<HIGHLIGHTSYNTAX>
+
<pre>
 
var foobar: String = foo.concat(bar);
 
var foobar: String = foo.concat(bar);
</HIGHLIGHTSYNTAX>
+
</pre>
  
 
==Scheme==
 
==Scheme==
<HIGHLIGHTSYNTAX language="scheme">
+
<pre>
 
(string-append a-string another-string)
 
(string-append a-string another-string)
</HIGHLIGHTSYNTAX>
+
</pre>
  
 
==Seed7==
 
==Seed7==
<HIGHLIGHTSYNTAX>
+
<pre>
 
foobar := foo & bar;
 
foobar := foo & bar;
</HIGHLIGHTSYNTAX>
+
</pre>
  
 
==Smalltalk==
 
==Smalltalk==
<HIGHLIGHTSYNTAX>
+
<pre>
 
foobar := foo, bar.
 
foobar := foo, bar.
</HIGHLIGHTSYNTAX>
+
</pre>
  
 
==Standard ML==
 
==Standard ML==
<HIGHLIGHTSYNTAX>
+
<pre>
 
val foobar = foo ^ bar
 
val foobar = foo ^ bar
</HIGHLIGHTSYNTAX>
+
</pre>
  
 
== Tcl ==
 
== Tcl ==
<HIGHLIGHTSYNTAX language="tcltk">
+
<pre>
 
  set a foo
 
  set a foo
 
  set b bar
 
  set b bar
Line 279: Line 414:
 
  set a foo
 
  set a foo
 
  set c ${a}bar
 
  set c ${a}bar
</HIGHLIGHTSYNTAX>
+
</pre>
  
 
==Visual Basic==
 
==Visual Basic==
<HIGHLIGHTSYNTAX>
+
<pre class="vb">
 
foobar = foo & bar
 
foobar = foo & bar
</HIGHLIGHTSYNTAX>
+
</pre>
  
 
==WinBatch==
 
==WinBatch==
Line 299: Line 434:
 
; Implemented since WinBatch version WB 2006D, Sep 22, DLL 5.12del.
 
; Implemented since WinBatch version WB 2006D, Sep 22, DLL 5.12del.
 
strD = strA : strB ; "foobar"
 
strD = strA : strB ; "foobar"
 +
 +
; Alternate 2 with Variable substitution.
 +
strC = "%strA%%strB%" ; "foobar"
  
 
Exit
 
Exit
Line 315: Line 453:
 
for i ({1..10}) var+=$i
 
for i ({1..10}) var+=$i
 
</pre>
 
</pre>
 +
 +
==Other titles==
 +
''This section is to help Shopobot search users find this page.  Feel free to add an alternate description of this page's content.''
 +
* join strings
 +
* combine two strings
 +
* add a string to the end of another string
  
 
[[Category:X86 Assembler]]
 
[[Category:X86 Assembler]]
 +
[[Category:Ada]]
 +
[[Category:AppleScript]]
 
[[Category:ASP]]
 
[[Category:ASP]]
 
[[Category:BASIC]]
 
[[Category:BASIC]]
 
[[Category:C]]
 
[[Category:C]]
 
[[Category:C++]]
 
[[Category:C++]]
 +
[[Category:Common Lisp]]
 +
[[Category:D]]
 
[[Category:Delphi]]
 
[[Category:Delphi]]
 +
[[Category:Erlang]]
 
[[Category:Gibiane]]
 
[[Category:Gibiane]]
 +
[[Category:Go]]
 +
[[Category:Groovy]]
 
[[Category:Haskell]]
 
[[Category:Haskell]]
 
[[Category:Java]]
 
[[Category:Java]]
 +
[[Category:JavaScript]]
 +
[[Category:Lua]]
 
[[Category:Matlab]]
 
[[Category:Matlab]]
 +
[[Category:Modula-3]]
 
[[Category:Objective-C]]
 
[[Category:Objective-C]]
 
[[Category:Objective Caml]]
 
[[Category:Objective Caml]]
 +
[[Category:Pascal]]
 
[[Category:Perl]]
 
[[Category:Perl]]
 
[[Category:PHP]]
 
[[Category:PHP]]
 
[[Category:PL/SQL]]
 
[[Category:PL/SQL]]
 
[[Category:Python]]
 
[[Category:Python]]
[[Category:PHP]]
 
 
[[Category:R]]
 
[[Category:R]]
 +
[[Category:Rexx]]
 +
[[Category:Ruby]]
 +
[[Category:Scala]]
 
[[Category:Scheme]]
 
[[Category:Scheme]]
 
[[Category:Seed7]]
 
[[Category:Seed7]]
 +
[[Category:Smalltalk]]
 
[[Category:Standard ML]]
 
[[Category:Standard ML]]
 
[[Category:Tcl]]
 
[[Category:Tcl]]
 +
[[Category:Visual Basic]]
 
[[Category:WinBatch]]
 
[[Category:WinBatch]]
 
[[Category:Zsh]]
 
[[Category:Zsh]]
  
 
[[Category:String]]
 
[[Category:String]]

Latest revision as of 18:08, 17 April 2012

Related content:

X86 Assembly[edit]

DATA SEGMENT

       STR1 DB "ENTER FIRST STRING HERE ->$"
       STR2 DB "ENTER SECOND STRING HERE ->$"
       STR3 DB "CONCATED STRING :->$"
       STR11 DB "FIRST STRING : ->$"
       STR22 DB "SECOND STRING: ->$"
       INSTR1 DB 20 DUP("$")
       INSTR2 DB 20 DUP("$")
       N DB ?
       N1 DB ?
       NEWLINE DB 10,13,"$"

DATA ENDS

CODE SEGMENT

       ASSUME DS:DATA,CS:CODE

START:

       MOV AX,DATA
       MOV DS,AX
       LEA SI,INSTR1
       LEA DI,INSTR2
GET STRING
       MOV AH,09H
       LEA DX,STR1
       INT 21H
       MOV AH,0AH
       MOV DX,SI
       INT 21H


       MOV AH,09H
       LEA DX,NEWLINE
       INT 21H
       MOV AH,09H
       LEA DX,STR2
       INT 21H
       MOV AH,0AH
       MOV DX,DI
       INT 21H


       MOV AH,09H
       LEA DX,NEWLINE
       INT 21H


PRINT THE STRING
       MOV AH,09H
       LEA DX,STR11
       INT 21H
       MOV AH,09H
       LEA DX,INSTR1+2
       INT 21H
       MOV AH,09H
       LEA DX,NEWLINE
       INT 21H
       MOV AH,09H
       LEA DX,STR22                    
       INT 21H
       MOV AH,09H
       LEA DX,INSTR2+2
       INT 21H
       MOV AH,09H
       LEA DX,NEWLINE
       INT 21H
CONCATINATION OF THE STRING
       LEA SI,INSTR1
       LEA DI,INSTR2
       MOV CX,00
       INC SI
    L1:INC SI
       CMP BYTE PTR[SI],"$"
       JNE L1
       ADD DI,2
       MOV BX,0
     L2:
      
       MOV BL,BYTE PTR[DI]
       MOV BYTE PTR[SI],BL
       
       INC SI
       INC DI
       CMP BYTE PTR[DI],"$"
       JNE L2
    L8:DEC SI
       CMP SI,2
       JNE L8


       MOV AH,09H
       LEA DX,NEWLINE
       INT 21H
       MOV AH,09H
       LEA DX,STR3
       INT 21H
       MOV AH,09H
       LEA DX,NEWLINE
       INT 21H


    L6:
       MOV BL,BYTE PTR[SI]
       MOV AH,02H
       MOV DL,BL
       INT 21H
       INC SI
       CMP BYTE PTR[SI],"$"
       JNE L6
MOV AH,09H
;       LEA DX,INSTR1+2
 ;      INT 21
       MOV AH,4CH
       INT 21H


CODE ENDS END START

Ada[edit]

Foo : Unbounded_String := Foo & Bar;

AppleScript[edit]

 set newString to aString & anotherString

ASP[edit]

Dim sSomeText
sSomeText = "This is some text" & " and this is some more text."

BASIC[edit]

foobar = foo + bar

C[edit]

strcat(destination, source);

The string at "destination" is modified. The programmer must ensure that "destination" points to a block of memory large enough to hold the length of the concatenated string, plus the null terminator; otherwise it will overflow the buffer. You need to #include <string.h> for it to work.

C++[edit]

foobar = foo + bar;
foo += bar; //modifies foo
foo.append(bar);

//assuming that "foo" and "bar" are std::string objects.

Common Lisp[edit]

(concatenate 'string a-string another-string)

Objective-C[edit]

 NSString *foobar = [aStringObject stringByAppendingString:anotherStringObject];

alternatively:

 NSString *foobar = [NSString stringWithFormat:@"%@%@", aStringObject, anotherStringObject];

Another solution:

 NSMutableString *foobar = [NSMutableString stringWithString:aStringObject];
 [foobar appendString: anotherStringObject];

D[edit]

Two strings:

string first = "abc";
string second = "def";
string sum = first ~ second;

Many strings:

string[] parts = ["abc", "def", "ghil"];
auto joined = parts.join("");

Delphi[edit]

foobar := 'foo' + 'bar' ;

Erlang[edit]

Foobar = "foo" ++ "bar".

Gibiane[edit]

foobar = concat: 'foo' string 'bar' ;

Go[edit]

foobar := foo + bar

Groovy[edit]

Dynamic variable:

foobar = foo + bar

Faster way:

foobar = "$foo$bar"

With static variable:

String foobar = "$foo$bar"

Haskell[edit]

foobar = foo ++ bar

Java[edit]

foobar = foo + bar;

Slightly faster way:

foobar = new StringBuilder(foo).append(bar).toString();

Slower, but thread-safe:

foobar = new StringBuffer(foo).append(bar).toString();

Javascript[edit]

var foobar = foo + bar;
var foobar = [foo,bar].join('');

Lua[edit]

foobar = foo .. bar

Matlab[edit]

foobar = ['foo' 'bar'];

Alternatively:

foobar = strcat(foo, bar);

Note: The second method trims spaces, while the first method does not.

Modula-3[edit]

Sample variable declaration:

VAR foo: TEXT := "Foo";
VAR bar: TEXT := "Bar";
VAR foobar : TEXT;

Sample code:

foobar := foo & bar;

OCaml[edit]

let foobar = foo ^ bar

Pascal[edit]

var foobar : String;
foobar := Concat(foo, bar);

Perl[edit]

 $foobar = $foo.$bar;  # concatenation
 $foo   .= $bar;       # assignment concatenation
 $foobar = "$foo$bar"; # interpolation

PHP[edit]

 $foobar = $foo.$bar;
 $foobar = "$foo$bar";
 $foo .= $bar;

PL/SQL[edit]

 foobar := foo || bar;

Python[edit]

foobar = foo + bar

Concatenate N strings:

list_of_strings = ['abc', 'def', 'ghi']
foobar = ''.join(list_of_strings)

Alternatively:

 foobar = '%s, %s' % ('abc', 'def')

R[edit]

foo = "string1"
bar = "string2"
foobar = paste(foo,bar,sep="")

Rexx[edit]

foobar = foo || bar

Ruby[edit]

one = "one"
two = "two"
string = one + two

# Alternatively:
string = "#{one}#{two}"

# Or even:
string = [ one, two ].join

Scala[edit]

var foobar: String = foo + bar;

Faster way:

var foobar: String = foo.concat(bar);

Scheme[edit]

(string-append a-string another-string)

Seed7[edit]

foobar := foo & bar;

Smalltalk[edit]

foobar := foo, bar.

Standard ML[edit]

val foobar = foo ^ bar

Tcl[edit]

 set a foo
 set b bar
 set c $a$b
 
# or
 set a foo
 set c ${a}bar

Visual Basic[edit]

foobar = foo & bar

WinBatch[edit]

; WinBatch. Concatenate two strings.

strA = "foo"
strB = "bar"

; Traditional string concatenation using the function StrCat ().
strC = StrCat (strA, strB) ; "foobar"

; Alternative string concatenation using the colon character.
; Implemented since WinBatch version WB 2006D, Sep 22, DLL 5.12del.
strD = strA : strB ; "foobar"

; Alternate 2 with Variable substitution.
strC = "%strA%%strB%" ; "foobar"

Exit
; This code example was written by Detlev Dalitz.20090706.2150.CEST

Zsh[edit]

a=foo
b=bar
c=$a$b

In loop

for i ({1..10}) var+=$i

Other titles[edit]

This section is to help Shopobot search users find this page. Feel free to add an alternate description of this page's content.

  • join strings
  • combine two strings
  • add a string to the end of another string