kazuyamaa/multi-language-messages-01 huggingface dataset:
Task: Primality by Wilson's theorem
Java: import java.math.BigInteger;

public class PrimaltyByWilsonsTheorem {

    public static void main(String[] args) {
        System.out.printf("Primes less than 100 testing by Wilson's Theorem%n");
        for ( int i = 0 ; i <= 100 ; i++ ) {
            if ( isPrime(i) ) {
                System.out.printf("%d ", i);
            }
        }
    }
    
    
    private static boolean isPrime(long p) {
        if ( p <= 1) {
            return false;
        }
        return fact(p-1).add(BigInteger.ONE).mod(BigInteger.valueOf(p)).compareTo(BigInteger.ZERO) == 0;
    }
    
    private static BigInteger fact(long n) {
        BigInteger fact = BigInteger.ONE;
        for ( int i = 2 ; i <= n ; i++ ) {
            fact = fact.multiply(BigInteger.valueOf(i));
        }
        return fact;
    }

}

Python: from math import factorial

def is_wprime(n):
    return n == 2 or (
        n > 1
        and n % 2 != 0
        and (factorial(n - 1) + 1) % n == 0
    )

if __name__ == '__main__':
    c = int(input('Enter upper limit: '))
    print(f'Primes under {c}:')
    print([n for n in range(c) if is_wprime(n)])
Task: Pick random element
C: #include <stdio.h>
#include <stdlib.h>
#include <time.h>
 
int main(){
   char array[] = { 'a', 'b', 'c','d','e','f','g','h','i','j' };
   int i;
   time_t t;
   srand((unsigned)time(&t));
   
   for(i=0;i<30;i++){
		printf("%c\n", array[rand()%10]);
   }
   
   return 0;
}

C++: #include <iostream>
#include <random>
#include <vector>

int main( ) {
   std::vector<int> numbers { 11 , 88 , -5 , 13 , 4 , 121 , 77 , 2 } ;
   std::random_device seed ;
   
   std::mt19937 engine( seed( ) ) ;
   
   std::uniform_int_distribution<int> choose( 0 , numbers.size( ) - 1 ) ;
   std::cout << "random element picked : " << numbers[ choose( engine ) ] 
      << " !\n" ;
   return 0 ;
}
Task: Pick random element
C: #include <stdio.h>
#include <stdlib.h>
#include <time.h>
 
int main(){
   char array[] = { 'a', 'b', 'c','d','e','f','g','h','i','j' };
   int i;
   time_t t;
   srand((unsigned)time(&t));
   
   for(i=0;i<30;i++){
		printf("%c\n", array[rand()%10]);
   }
   
   return 0;
}

Go: package main

import (
    "fmt"
    "math/rand"
    "time"
)

var list = []string{"bleen", "fuligin", "garrow", "grue", "hooloovoo"}

func main() {
    rand.Seed(time.Now().UnixNano())
    fmt.Println(list[rand.Intn(len(list))])
}
Task: Pick random element
C: #include <stdio.h>
#include <stdlib.h>
#include <time.h>
 
int main(){
   char array[] = { 'a', 'b', 'c','d','e','f','g','h','i','j' };
   int i;
   time_t t;
   srand((unsigned)time(&t));
   
   for(i=0;i<30;i++){
		printf("%c\n", array[rand()%10]);
   }
   
   return 0;
}

Java: import java.util.Random;
...
int[] array = {1,2,3};
return array[new Random().nextInt(array.length)];
Task: Pick random element
C: #include <stdio.h>
#include <stdlib.h>
#include <time.h>
 
int main(){
   char array[] = { 'a', 'b', 'c','d','e','f','g','h','i','j' };
   int i;
   time_t t;
   srand((unsigned)time(&t));
   
   for(i=0;i<30;i++){
		printf("%c\n", array[rand()%10]);
   }
   
   return 0;
}

VB: Option Explicit

Sub Main_Pick_Random_Element()
    Debug.Print Pick_Random_Element(Array(1, 2, 3, 4, 5, #11/24/2017#, "azerty"))
End Sub

Function Pick_Random_Element(myArray)
    Randomize Timer
    Pick_Random_Element = myArray(Int((Rnd * (UBound(myArray) - LBound(myArray) + 1) + LBound(myArray))))
End Function
Task: Pick random element
C++: #include <iostream>
#include <random>
#include <vector>

int main( ) {
   std::vector<int> numbers { 11 , 88 , -5 , 13 , 4 , 121 , 77 , 2 } ;
   std::random_device seed ;
   
   std::mt19937 engine( seed( ) ) ;
   
   std::uniform_int_distribution<int> choose( 0 , numbers.size( ) - 1 ) ;
   std::cout << "random element picked : " << numbers[ choose( engine ) ] 
      << " !\n" ;
   return 0 ;
}

Java: import java.util.Random;
...
int[] array = {1,2,3};
return array[new Random().nextInt(array.length)];
Task: Pick random element
C++: #include <iostream>
#include <random>
#include <vector>

int main( ) {
   std::vector<int> numbers { 11 , 88 , -5 , 13 , 4 , 121 , 77 , 2 } ;
   std::random_device seed ;
   
   std::mt19937 engine( seed( ) ) ;
   
   std::uniform_int_distribution<int> choose( 0 , numbers.size( ) - 1 ) ;
   std::cout << "random element picked : " << numbers[ choose( engine ) ] 
      << " !\n" ;
   return 0 ;
}

Python: >>> import random
>>> random.choice(['foo', 'bar', 'baz'])
'baz'
Task: Pick random element
C#: using System;
using System.Collections.Generic;

class RandomElementPicker {
  static void Main() {
    var list = new List<int>(new[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
    var rng = new Random();
    var randomElement = list[rng.Next(list.Count)];
    Console.WriteLine("I picked element {0}", randomElement);
  }
}

Go: package main

import (
    "fmt"
    "math/rand"
    "time"
)

var list = []string{"bleen", "fuligin", "garrow", "grue", "hooloovoo"}

func main() {
    rand.Seed(time.Now().UnixNano())
    fmt.Println(list[rand.Intn(len(list))])
}
Task: Pick random element
C#: using System;
using System.Collections.Generic;

class RandomElementPicker {
  static void Main() {
    var list = new List<int>(new[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
    var rng = new Random();
    var randomElement = list[rng.Next(list.Count)];
    Console.WriteLine("I picked element {0}", randomElement);
  }
}

Python: >>> import random
>>> random.choice(['foo', 'bar', 'baz'])
'baz'
Task: Pick random element
C#: using System;
using System.Collections.Generic;

class RandomElementPicker {
  static void Main() {
    var list = new List<int>(new[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
    var rng = new Random();
    var randomElement = list[rng.Next(list.Count)];
    Console.WriteLine("I picked element {0}", randomElement);
  }
}

VB: Option Explicit

Sub Main_Pick_Random_Element()
    Debug.Print Pick_Random_Element(Array(1, 2, 3, 4, 5, #11/24/2017#, "azerty"))
End Sub

Function Pick_Random_Element(myArray)
    Randomize Timer
    Pick_Random_Element = myArray(Int((Rnd * (UBound(myArray) - LBound(myArray) + 1) + LBound(myArray))))
End Function
Task: Pick random element
Java: import java.util.Random;
...
int[] array = {1,2,3};
return array[new Random().nextInt(array.length)]; 

Python: >>> import random
>>> random.choice(['foo', 'bar', 'baz'])
'baz'
Task: Pick random element
Java: import java.util.Random;
...
int[] array = {1,2,3};
return array[new Random().nextInt(array.length)]; 

VB: Option Explicit

Sub Main_Pick_Random_Element()
    Debug.Print Pick_Random_Element(Array(1, 2, 3, 4, 5, #11/24/2017#, "azerty"))
End Sub

Function Pick_Random_Element(myArray)
    Randomize Timer
    Pick_Random_Element = myArray(Int((Rnd * (UBound(myArray) - LBound(myArray) + 1) + LBound(myArray))))
End Function
Task: Pick random element
Go: package main

import (
    "fmt"
    "math/rand"
    "time"
)

var list = []string{"bleen", "fuligin", "garrow", "grue", "hooloovoo"}

func main() {
    rand.Seed(time.Now().UnixNano())
    fmt.Println(list[rand.Intn(len(list))])
}

Python: >>> import random
>>> random.choice(['foo', 'bar', 'baz'])
'baz'
Task: Pick random element
Go: package main

import (
    "fmt"
    "math/rand"
    "time"
)

var list = []string{"bleen", "fuligin", "garrow", "grue", "hooloovoo"}

func main() {
    rand.Seed(time.Now().UnixNano())
    fmt.Println(list[rand.Intn(len(list))])
}

VB: Option Explicit

Sub Main_Pick_Random_Element()
    Debug.Print Pick_Random_Element(Array(1, 2, 3, 4, 5, #11/24/2017#, "azerty"))
End Sub

Function Pick_Random_Element(myArray)
    Randomize Timer
    Pick_Random_Element = myArray(Int((Rnd * (UBound(myArray) - LBound(myArray) + 1) + LBound(myArray))))
End Function
Task: Pick random element
Python: >>> import random
>>> random.choice(['foo', 'bar', 'baz'])
'baz'

VB: Option Explicit

Sub Main_Pick_Random_Element()
    Debug.Print Pick_Random_Element(Array(1, 2, 3, 4, 5, #11/24/2017#, "azerty"))
End Sub

Function Pick_Random_Element(myArray)
    Randomize Timer
    Pick_Random_Element = myArray(Int((Rnd * (UBound(myArray) - LBound(myArray) + 1) + LBound(myArray))))
End Function
Task: Pick random element
C: #include <stdio.h>
#include <stdlib.h>
#include <time.h>
 
int main(){
   char array[] = { 'a', 'b', 'c','d','e','f','g','h','i','j' };
   int i;
   time_t t;
   srand((unsigned)time(&t));
   
   for(i=0;i<30;i++){
		printf("%c\n", array[rand()%10]);
   }
   
   return 0;
}

C#: using System;
using System.Collections.Generic;

class RandomElementPicker {
  static void Main() {
    var list = new List<int>(new[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
    var rng = new Random();
    var randomElement = list[rng.Next(list.Count)];
    Console.WriteLine("I picked element {0}", randomElement);
  }
}
Task: Pick random element
C++: #include <iostream>
#include <random>
#include <vector>

int main( ) {
   std::vector<int> numbers { 11 , 88 , -5 , 13 , 4 , 121 , 77 , 2 } ;
   std::random_device seed ;
   
   std::mt19937 engine( seed( ) ) ;
   
   std::uniform_int_distribution<int> choose( 0 , numbers.size( ) - 1 ) ;
   std::cout << "random element picked : " << numbers[ choose( engine ) ] 
      << " !\n" ;
   return 0 ;
}

VB: Option Explicit

Sub Main_Pick_Random_Element()
    Debug.Print Pick_Random_Element(Array(1, 2, 3, 4, 5, #11/24/2017#, "azerty"))
End Sub

Function Pick_Random_Element(myArray)
    Randomize Timer
    Pick_Random_Element = myArray(Int((Rnd * (UBound(myArray) - LBound(myArray) + 1) + LBound(myArray))))
End Function
Task: Pick random element
C#: using System;
using System.Collections.Generic;

class RandomElementPicker {
  static void Main() {
    var list = new List<int>(new[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
    var rng = new Random();
    var randomElement = list[rng.Next(list.Count)];
    Console.WriteLine("I picked element {0}", randomElement);
  }
}

Java: import java.util.Random;
...
int[] array = {1,2,3};
return array[new Random().nextInt(array.length)];
Task: Pick random element
C: #include <stdio.h>
#include <stdlib.h>
#include <time.h>
 
int main(){
   char array[] = { 'a', 'b', 'c','d','e','f','g','h','i','j' };
   int i;
   time_t t;
   srand((unsigned)time(&t));
   
   for(i=0;i<30;i++){
		printf("%c\n", array[rand()%10]);
   }
   
   return 0;
}

Python: >>> import random
>>> random.choice(['foo', 'bar', 'baz'])
'baz'
Task: Pick random element
C#: using System;
using System.Collections.Generic;

class RandomElementPicker {
  static void Main() {
    var list = new List<int>(new[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
    var rng = new Random();
    var randomElement = list[rng.Next(list.Count)];
    Console.WriteLine("I picked element {0}", randomElement);
  }
}

C++: #include <iostream>
#include <random>
#include <vector>

int main( ) {
   std::vector<int> numbers { 11 , 88 , -5 , 13 , 4 , 121 , 77 , 2 } ;
   std::random_device seed ;
   
   std::mt19937 engine( seed( ) ) ;
   
   std::uniform_int_distribution<int> choose( 0 , numbers.size( ) - 1 ) ;
   std::cout << "random element picked : " << numbers[ choose( engine ) ] 
      << " !\n" ;
   return 0 ;
}
Task: Pick random element
C++: #include <iostream>
#include <random>
#include <vector>

int main( ) {
   std::vector<int> numbers { 11 , 88 , -5 , 13 , 4 , 121 , 77 , 2 } ;
   std::random_device seed ;
   
   std::mt19937 engine( seed( ) ) ;
   
   std::uniform_int_distribution<int> choose( 0 , numbers.size( ) - 1 ) ;
   std::cout << "random element picked : " << numbers[ choose( engine ) ] 
      << " !\n" ;
   return 0 ;
}

Go: package main

import (
    "fmt"
    "math/rand"
    "time"
)

var list = []string{"bleen", "fuligin", "garrow", "grue", "hooloovoo"}

func main() {
    rand.Seed(time.Now().UnixNano())
    fmt.Println(list[rand.Intn(len(list))])
}
Task: Pick random element
Go: package main

import (
    "fmt"
    "math/rand"
    "time"
)

var list = []string{"bleen", "fuligin", "garrow", "grue", "hooloovoo"}

func main() {
    rand.Seed(time.Now().UnixNano())
    fmt.Println(list[rand.Intn(len(list))])
}

Java: import java.util.Random;
...
int[] array = {1,2,3};
return array[new Random().nextInt(array.length)];
Task: Pick random element
C: #include <stdio.h>
#include <stdlib.h>
#include <time.h>
 
int main(){
   char array[] = { 'a', 'b', 'c','d','e','f','g','h','i','j' };
   int i;
   time_t t;
   srand((unsigned)time(&t));
   
   for(i=0;i<30;i++){
		printf("%c\n", array[rand()%10]);
   }
   
   return 0;
}

PHP: $arr = array('foo', 'bar', 'baz');
$x = $arr[array_rand($arr)];
Task: Pick random element
C#: using System;
using System.Collections.Generic;

class RandomElementPicker {
  static void Main() {
    var list = new List<int>(new[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
    var rng = new Random();
    var randomElement = list[rng.Next(list.Count)];
    Console.WriteLine("I picked element {0}", randomElement);
  }
}

PHP: $arr = array('foo', 'bar', 'baz');
$x = $arr[array_rand($arr)];
Task: Pick random element
C++: #include <iostream>
#include <random>
#include <vector>

int main( ) {
   std::vector<int> numbers { 11 , 88 , -5 , 13 , 4 , 121 , 77 , 2 } ;
   std::random_device seed ;
   
   std::mt19937 engine( seed( ) ) ;
   
   std::uniform_int_distribution<int> choose( 0 , numbers.size( ) - 1 ) ;
   std::cout << "random element picked : " << numbers[ choose( engine ) ] 
      << " !\n" ;
   return 0 ;
}

PHP: $arr = array('foo', 'bar', 'baz');
$x = $arr[array_rand($arr)];
Task: Pick random element
Go: package main

import (
    "fmt"
    "math/rand"
    "time"
)

var list = []string{"bleen", "fuligin", "garrow", "grue", "hooloovoo"}

func main() {
    rand.Seed(time.Now().UnixNano())
    fmt.Println(list[rand.Intn(len(list))])
}

PHP: $arr = array('foo', 'bar', 'baz');
$x = $arr[array_rand($arr)];
Task: Pick random element
Java: import java.util.Random;
...
int[] array = {1,2,3};
return array[new Random().nextInt(array.length)]; 

PHP: $arr = array('foo', 'bar', 'baz');
$x = $arr[array_rand($arr)];
Task: Pick random element
Python: >>> import random
>>> random.choice(['foo', 'bar', 'baz'])
'baz'

PHP: $arr = array('foo', 'bar', 'baz');
$x = $arr[array_rand($arr)];
Task: Pick random element
VB: Option Explicit

Sub Main_Pick_Random_Element()
    Debug.Print Pick_Random_Element(Array(1, 2, 3, 4, 5, #11/24/2017#, "azerty"))
End Sub

Function Pick_Random_Element(myArray)
    Randomize Timer
    Pick_Random_Element = myArray(Int((Rnd * (UBound(myArray) - LBound(myArray) + 1) + LBound(myArray))))
End Function

PHP: $arr = array('foo', 'bar', 'baz');
$x = $arr[array_rand($arr)];
Task: URL encoding
C: #include <stdio.h>
#include <ctype.h>
 
char rfc3986[256] = {0};
char html5[256] = {0};


void encode(const char *s, char *enc, char *tb)
{
	for (; *s; s++) {
		if (tb[*s]) sprintf(enc, "%c", tb[*s]);
		else        sprintf(enc, "%%%02X", *s);
		while (*++enc);
	}
}
 
int main()
{
	const char url[] = "http:
	char enc[(strlen(url) * 3) + 1];
 
	int i;
	for (i = 0; i < 256; i++) {
		rfc3986[i] = isalnum(i)||i == '~'||i == '-'||i == '.'||i == '_'
			? i : 0;
		html5[i] = isalnum(i)||i == '*'||i == '-'||i == '.'||i == '_'
			? i : (i == ' ') ? '+' : 0;
	}
 
	encode(url, enc, rfc3986);
	puts(enc);
 
	return 0;
}

C++: #include <QByteArray>
#include <iostream>

int main( ) {
   QByteArray text ( "http:
   QByteArray encoded( text.toPercentEncoding( ) ) ;
   std::cout << encoded.data( ) << '\n' ;
   return 0 ;
}
Task: URL encoding
C: #include <stdio.h>
#include <ctype.h>
 
char rfc3986[256] = {0};
char html5[256] = {0};


void encode(const char *s, char *enc, char *tb)
{
	for (; *s; s++) {
		if (tb[*s]) sprintf(enc, "%c", tb[*s]);
		else        sprintf(enc, "%%%02X", *s);
		while (*++enc);
	}
}
 
int main()
{
	const char url[] = "http:
	char enc[(strlen(url) * 3) + 1];
 
	int i;
	for (i = 0; i < 256; i++) {
		rfc3986[i] = isalnum(i)||i == '~'||i == '-'||i == '.'||i == '_'
			? i : 0;
		html5[i] = isalnum(i)||i == '*'||i == '-'||i == '.'||i == '_'
			? i : (i == ' ') ? '+' : 0;
	}
 
	encode(url, enc, rfc3986);
	puts(enc);
 
	return 0;
}

Java: import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

public class Main
{
    public static void main(String[] args) throws UnsupportedEncodingException
    {
        String normal = "http:
        String encoded = URLEncoder.encode(normal, "utf-8");
        System.out.println(encoded);
    }
}
Task: URL encoding
C: #include <stdio.h>
#include <ctype.h>
 
char rfc3986[256] = {0};
char html5[256] = {0};


void encode(const char *s, char *enc, char *tb)
{
	for (; *s; s++) {
		if (tb[*s]) sprintf(enc, "%c", tb[*s]);
		else        sprintf(enc, "%%%02X", *s);
		while (*++enc);
	}
}
 
int main()
{
	const char url[] = "http:
	char enc[(strlen(url) * 3) + 1];
 
	int i;
	for (i = 0; i < 256; i++) {
		rfc3986[i] = isalnum(i)||i == '~'||i == '-'||i == '.'||i == '_'
			? i : 0;
		html5[i] = isalnum(i)||i == '*'||i == '-'||i == '.'||i == '_'
			? i : (i == ' ') ? '+' : 0;
	}
 
	encode(url, enc, rfc3986);
	puts(enc);
 
	return 0;
}

Python: import urllib
s = 'http://foo/bar/'
s = urllib.quote(s)
Task: URL encoding
C: #include <stdio.h>
#include <ctype.h>
 
char rfc3986[256] = {0};
char html5[256] = {0};


void encode(const char *s, char *enc, char *tb)
{
	for (; *s; s++) {
		if (tb[*s]) sprintf(enc, "%c", tb[*s]);
		else        sprintf(enc, "%%%02X", *s);
		while (*++enc);
	}
}
 
int main()
{
	const char url[] = "http:
	char enc[(strlen(url) * 3) + 1];
 
	int i;
	for (i = 0; i < 256; i++) {
		rfc3986[i] = isalnum(i)||i == '~'||i == '-'||i == '.'||i == '_'
			? i : 0;
		html5[i] = isalnum(i)||i == '*'||i == '-'||i == '.'||i == '_'
			? i : (i == ' ') ? '+' : 0;
	}
 
	encode(url, enc, rfc3986);
	puts(enc);
 
	return 0;
}

VB:   Dim URL As String = "http://foo bar/"
  URL = EncodeURLComponent(URL)
  Print(URL)
Task: URL encoding
C++: #include <QByteArray>
#include <iostream>

int main( ) {
   QByteArray text ( "http:
   QByteArray encoded( text.toPercentEncoding( ) ) ;
   std::cout << encoded.data( ) << '\n' ;
   return 0 ;
}

Go: package main

import (
    "fmt"
    "net/url"
)

func main() {
    fmt.Println(url.QueryEscape("http:
}
Task: URL encoding
C++: #include <QByteArray>
#include <iostream>

int main( ) {
   QByteArray text ( "http:
   QByteArray encoded( text.toPercentEncoding( ) ) ;
   std::cout << encoded.data( ) << '\n' ;
   return 0 ;
}

Java: import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

public class Main
{
    public static void main(String[] args) throws UnsupportedEncodingException
    {
        String normal = "http:
        String encoded = URLEncoder.encode(normal, "utf-8");
        System.out.println(encoded);
    }
}
Task: URL encoding
C++: #include <QByteArray>
#include <iostream>

int main( ) {
   QByteArray text ( "http:
   QByteArray encoded( text.toPercentEncoding( ) ) ;
   std::cout << encoded.data( ) << '\n' ;
   return 0 ;
}

Python: import urllib
s = 'http://foo/bar/'
s = urllib.quote(s)
Task: URL encoding
C++: #include <QByteArray>
#include <iostream>

int main( ) {
   QByteArray text ( "http:
   QByteArray encoded( text.toPercentEncoding( ) ) ;
   std::cout << encoded.data( ) << '\n' ;
   return 0 ;
}

VB:   Dim URL As String = "http://foo bar/"
  URL = EncodeURLComponent(URL)
  Print(URL)
Task: URL encoding
Java: import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

public class Main
{
    public static void main(String[] args) throws UnsupportedEncodingException
    {
        String normal = "http:
        String encoded = URLEncoder.encode(normal, "utf-8");
        System.out.println(encoded);
    }
}

Python: import urllib
s = 'http://foo/bar/'
s = urllib.quote(s)
Task: URL encoding
Java: import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

public class Main
{
    public static void main(String[] args) throws UnsupportedEncodingException
    {
        String normal = "http:
        String encoded = URLEncoder.encode(normal, "utf-8");
        System.out.println(encoded);
    }
}

VB:   Dim URL As String = "http://foo bar/"
  URL = EncodeURLComponent(URL)
  Print(URL)
Task: URL encoding
Go: package main

import (
    "fmt"
    "net/url"
)

func main() {
    fmt.Println(url.QueryEscape("http:
}

Python: import urllib
s = 'http://foo/bar/'
s = urllib.quote(s)
Task: URL encoding
Go: package main

import (
    "fmt"
    "net/url"
)

func main() {
    fmt.Println(url.QueryEscape("http:
}

VB:   Dim URL As String = "http://foo bar/"
  URL = EncodeURLComponent(URL)
  Print(URL)
Task: URL encoding
Python: import urllib
s = 'http://foo/bar/'
s = urllib.quote(s)

VB:   Dim URL As String = "http://foo bar/"
  URL = EncodeURLComponent(URL)
  Print(URL)
Task: URL encoding
C: #include <stdio.h>
#include <ctype.h>
 
char rfc3986[256] = {0};
char html5[256] = {0};


void encode(const char *s, char *enc, char *tb)
{
	for (; *s; s++) {
		if (tb[*s]) sprintf(enc, "%c", tb[*s]);
		else        sprintf(enc, "%%%02X", *s);
		while (*++enc);
	}
}
 
int main()
{
	const char url[] = "http:
	char enc[(strlen(url) * 3) + 1];
 
	int i;
	for (i = 0; i < 256; i++) {
		rfc3986[i] = isalnum(i)||i == '~'||i == '-'||i == '.'||i == '_'
			? i : 0;
		html5[i] = isalnum(i)||i == '*'||i == '-'||i == '.'||i == '_'
			? i : (i == ' ') ? '+' : 0;
	}
 
	encode(url, enc, rfc3986);
	puts(enc);
 
	return 0;
}

Go: package main

import (
    "fmt"
    "net/url"
)

func main() {
    fmt.Println(url.QueryEscape("http:
}
Task: URL encoding
Go: package main

import (
    "fmt"
    "net/url"
)

func main() {
    fmt.Println(url.QueryEscape("http:
}

Java: import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

public class Main
{
    public static void main(String[] args) throws UnsupportedEncodingException
    {
        String normal = "http:
        String encoded = URLEncoder.encode(normal, "utf-8");
        System.out.println(encoded);
    }
}
Task: URL encoding
C: #include <stdio.h>
#include <ctype.h>
 
char rfc3986[256] = {0};
char html5[256] = {0};


void encode(const char *s, char *enc, char *tb)
{
	for (; *s; s++) {
		if (tb[*s]) sprintf(enc, "%c", tb[*s]);
		else        sprintf(enc, "%%%02X", *s);
		while (*++enc);
	}
}
 
int main()
{
	const char url[] = "http:
	char enc[(strlen(url) * 3) + 1];
 
	int i;
	for (i = 0; i < 256; i++) {
		rfc3986[i] = isalnum(i)||i == '~'||i == '-'||i == '.'||i == '_'
			? i : 0;
		html5[i] = isalnum(i)||i == '*'||i == '-'||i == '.'||i == '_'
			? i : (i == ' ') ? '+' : 0;
	}
 
	encode(url, enc, rfc3986);
	puts(enc);
 
	return 0;
}

PHP: <?php
$s = 'http://foo/bar/';
$s = rawurlencode($s);
?>
Task: URL encoding
C++: #include <QByteArray>
#include <iostream>

int main( ) {
   QByteArray text ( "http:
   QByteArray encoded( text.toPercentEncoding( ) ) ;
   std::cout << encoded.data( ) << '\n' ;
   return 0 ;
}

PHP: <?php
$s = 'http://foo/bar/';
$s = rawurlencode($s);
?>
Task: URL encoding
Go: package main

import (
    "fmt"
    "net/url"
)

func main() {
    fmt.Println(url.QueryEscape("http:
}

PHP: <?php
$s = 'http://foo/bar/';
$s = rawurlencode($s);
?>
Task: URL encoding
Java: import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

public class Main
{
    public static void main(String[] args) throws UnsupportedEncodingException
    {
        String normal = "http:
        String encoded = URLEncoder.encode(normal, "utf-8");
        System.out.println(encoded);
    }
}

PHP: <?php
$s = 'http://foo/bar/';
$s = rawurlencode($s);
?>
Task: URL encoding
Python: import urllib
s = 'http://foo/bar/'
s = urllib.quote(s)

PHP: <?php
$s = 'http://foo/bar/';
$s = rawurlencode($s);
?>
Task: URL encoding
VB:   Dim URL As String = "http://foo bar/"
  URL = EncodeURLComponent(URL)
  Print(URL)

PHP: <?php
$s = 'http://foo/bar/';
$s = rawurlencode($s);
?>