Update all new Tasks

This commit is contained in:
Ingy döt Net 2015-02-20 09:02:09 -05:00
parent 00a190b0a6
commit 91df62d461
5697 changed files with 93386 additions and 804 deletions

View file

@ -0,0 +1,9 @@
{{basic data operation}}
[[Category:String manipulation]] [[Category: String manipulation]] [[Category:Simple]]
{{omit from|bc|No string operations in bc}}
{{omit from|dc|No string operations in dc}}
Create a string variable equal to any text value.
Prepend the string variable with another string literal.
If your language supports any idiomatic ways to do this without referring to the variable twice in one expression, include such solutions.
To illustrate the operation, show the content of the variable.

View file

@ -0,0 +1,2 @@
---
note: Basic language learning

View file

@ -0,0 +1,6 @@
#!/usr/bin/a68g --script #
# -*- coding: utf-8 -*- #
STRING str := "12345678";
"0" +=: str;
print(str)

View file

@ -0,0 +1,7 @@
# syntax: GAWK -f STRING_PREPEND.AWK
BEGIN {
s = "bar"
s = "foo" s
print(s)
exit(0)
}

View file

@ -0,0 +1,3 @@
s := "foo"
s := s "bar"
Msgbox % s

View file

@ -0,0 +1,3 @@
S$ = " World!"
S$ = "Hello" + S$
PRINT S$

View file

@ -0,0 +1,3 @@
World!:?string
& str$("Hello " !string):?string
& out$!string

View file

@ -0,0 +1,13 @@
include <vector>
#include <algorithm>
#include <string>
#include <iostream>
int main( ) {
std::vector<std::string> myStrings { "prepended to" , "my string" } ;
std::string prepended = std::accumulate( myStrings.begin( ) ,
myStrings.end( ) , std::string( "" ) , []( std::string a ,
std::string b ) { return a + b ; } ) ;
std::cout << prepended << std::endl ;
return 0 ;
}

View file

@ -0,0 +1,15 @@
using System;
namespace PrependString
{
class Program
{
static void Main(string[] args)
{
string str = "World";
str = "Hello " + str;
Console.WriteLine(str);
Console.ReadKey();
}
}
}

View file

@ -0,0 +1,14 @@
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
char str[100]="my String";
char *cstr="Changed ";
char *dup;
sprintf(str,"%s%s",cstr,(dup=strdup(str)));
free(dup);
printf("%s\n",str);
return 0;
}

View file

@ -0,0 +1,12 @@
>>SOURCE FREE
PROGRAM-ID. prepend.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 str PIC X(30) VALUE "world!".
PROCEDURE DIVISION.
MOVE FUNCTION CONCATENATE("Hello, ", str) TO str
DISPLAY str
.
END PROGRAM prepend.

View file

@ -0,0 +1,5 @@
(def s (ref "World"))
(dosync (alter s #(str "Hello " %)))
user=> @s
"Hello World"

View file

@ -0,0 +1,7 @@
(defmacro prependf (s &rest strs)
"Prepend the given string variable with additional strings. The string variable is modified in-place."
`(setf ,s (concatenate 'string ,@strs ,s)))
(defvar *str* "foo")
(prependf *str* "bar")
(format T "~a~%" *str*)

View file

@ -0,0 +1,7 @@
import std.stdio;
void main() {
string s = "world!";
s = "Hello " ~ s;
writeln(s);
}

View file

@ -0,0 +1,3 @@
local :s "world!"
set :s concat( "Hello " s)
!print s

View file

@ -0,0 +1,2 @@
"world"
"Hello " prepend

View file

@ -0,0 +1,2 @@
s := "world!"
s = "Hello, " + s

View file

@ -0,0 +1,2 @@
Prelude> let f = (++" World!")
Prelude> f "Hello"

View file

@ -0,0 +1,2 @@
s := "world!"
s := "Hello, " || s

View file

@ -0,0 +1,6 @@
s=: 'value'
s
value
s=: 'new ',s
s
new value

View file

@ -0,0 +1,7 @@
public class Prepend {
public static void main(String[] args) {
String s = "world!";
System.out.println("Hello " + s);
}
}

View file

@ -0,0 +1,2 @@
s = "world!"
s = "Hello " * s

View file

@ -0,0 +1,3 @@
s = "12345678"
s = "0" .. s
print(s)

View file

@ -0,0 +1,3 @@
s = "12345678"
s = string.format("%s%s", "0", s)
print(s)

View file

@ -0,0 +1,3 @@
s = "12345678"
s = table.concat({"0", s})
print(s)

View file

@ -0,0 +1,2 @@
a = "any text value";
a = "another string literal" <> a (* using concatenation (no built-in prepend) *)

View file

@ -0,0 +1,9 @@
:- module string_prepend.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module string.
main(!IO) :-
S = "World!\n",
io.write_string("Hello " ++ S, !IO).

View file

@ -0,0 +1,3 @@
s_ = 'world!'
s_ = 'Hello, 's_
say s_

View file

@ -0,0 +1,3 @@
(setq str "bar")
(push "foo" str)
(println str)

View file

@ -0,0 +1,2 @@
s = "world!";
s = Str("Hello, ", s)

View file

@ -0,0 +1,6 @@
Pre_Cat: procedure options (main); /* 2 November 2013 */
declare s character (100) varying;
s = ' bowl';
s = 'dust' || s;
put (s);
end Pre_Cat;

View file

@ -0,0 +1,17 @@
program StringPrepend;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes
{ you can add units after this };
var
s: String = ' World !';
begin
s := 'Hello' + s;
WriteLn(S);
ReadLn;
end.

View file

@ -0,0 +1,24 @@
# explicit concatentation
$_ = 'byte';
$_ = 'kilo' ~ $_;
.say;
# interpolation as concatenation
$_ = 'buck';
$_ = "mega$_";
.say;
# lvalue substr
$_ = 'bit';
substr-rw($_,0,0) = 'nano';
.say;
# regex substitution
$_ = 'fortnight';
s[^] = 'micro';
.say;
# reversed append assignment
$_ = 'cooper';
$_ [R~]= 'mini';
.say;

View file

@ -0,0 +1,3 @@
my $str = 'bar';
substr $str, 0, 0, 'Foo';
print $str;

View file

@ -0,0 +1,3 @@
(setq Str1 "12345678!")
(setq Str1 (pack "0" Str1))
(println Str1)

View file

@ -0,0 +1,12 @@
:- op(200, xfx, user:(=+)).
%% +Prepend =+ +Chars
%
% Will destructively update Chars
% So that Chars = Prepend prefixed to Chars.
% eazar001 in ##prolog helped refine this approach.
[X|Xs] =+ Chars :-
append(Xs, Chars, Rest),
nb_setarg(2, Chars, Rest),
nb_setarg(1, Chars, X).

View file

@ -0,0 +1,2 @@
?- Str = `World!`, `Hello, ` =+ Str.
Str = "Hello, World!".

View file

@ -0,0 +1,8 @@
S$ = " World!"
S$ = "Hello" + S$
If OpenConsole()
PrintN(S$)
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit"): Input()
CloseConsole()
EndIf

View file

@ -0,0 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
s = "12345678"
s = "0" + s # by concatenation
print(s)

View file

@ -0,0 +1 @@
Data source: http://rosettacode.org/wiki/String_prepend

View file

@ -0,0 +1,17 @@
/*──────────────── using literal abuttal. */
/*──────────────── this won't work as the first */
/*──────────────── variable name is X or B */
zz='llo world!'
zz='he'zz
say zz
/*──────────────── using literal concatenation. */
gg = "llo world!"
gg = 'he' || gg
say gg
/*──────────────── using variable concatenation.*/
aString = 'llo world!'
bString = "he"
aString = bString || aString
say aString

View file

@ -0,0 +1,12 @@
;there is no built-in way to set! prepend in racket
(define str "foo")
(set! str (string-append "bar " str))
(displayln str)
;but you can create a quick macro to solve that problem
(define-syntax-rule (set-prepend! str value)
(set! str (string-append value str)))
(define macrostr " bar")
(set-prepend! macrostr "foo")
(displayln macrostr)

View file

@ -0,0 +1,3 @@
str = "llo world"
str.prepend("He")
p str #=> "Hello world"

View file

@ -0,0 +1,5 @@
val s = "World" // Immutables are recommended //> s : String = World
val f2 = () => ", " //Function assigned to variable
//> f2 : () => String = <function0>
val s1 = "Hello" + f2() + s //> s1 : String = Hello, World
println(s1); //> Hello, World

View file

@ -0,0 +1,9 @@
$ include "seed7_05.s7i";
const proc: main is func
local
var string: s is "world!";
begin
s := "Hello " & s;
writeln(s);
end func;

View file

@ -0,0 +1,3 @@
set s "llo world"
set s "he$s"
puts $s

View file

@ -0,0 +1,6 @@
Function StringPrepend()
Dim s As String
s = "bar"
s = "foo" & s
Debug.Print s
End Function