Instruction
stringlengths
45
106
input_code
stringlengths
1
13.7k
output_code
stringlengths
1
13.7k
Rewrite this program in Java while keeping its functionality equivalent to the PowerShell version.
$string = 'alphaBETA' $lower = $string.ToLower() $upper = $string.ToUpper() $title = (Get-Culture).TextInfo.ToTitleCase($string) $lower, $upper, $title
String str = "alphaBETA"; System.out.println(str.toUpperCase()); System.out.println(str.toLowerCase()); System.out.println("äàâáçñßæεбế".toUpperCase()); System.out.println("ÄÀÂÁÇÑSSÆΕБẾ".toLowerCase());
Convert this PowerShell snippet to Python and keep its semantics consistent.
$string = 'alphaBETA' $lower = $string.ToLower() $upper = $string.ToUpper() $title = (Get-Culture).TextInfo.ToTitleCase($string) $lower, $upper, $title
s = "alphaBETA" print s.upper() print s.lower() print s.swapcase() print "fOo bAR".capitalize() print "fOo bAR".title() import string print string.capwords("fOo bAR")
Rewrite the snippet below in VB so it works the same as the original PowerShell code.
$string = 'alphaBETA' $lower = $string.ToLower() $upper = $string.ToUpper() $title = (Get-Culture).TextInfo.ToTitleCase($string) $lower, $upper, $title
Sub Main() Const TESTSTRING As String = "alphaBETA" Debug.Print "initial = " _ & TESTSTRING Debug.Print "uppercase = " _ & UCase(TESTSTRING) Debug.Print "lowercase = " _ & LCase(TESTSTRING) Debug.Print "first letter capitalized = " _ & StrConv(TESTSTRING, vbProperCase) Debug.Print "length (in characters) = " _ & CStr(Len(TESTSTRING)) Debug.Print "length (in bytes) = " _ & CStr(LenB(TESTSTRING)) Debug.Print "reversed = " _ & StrReverse(TESTSTRING) Debug.Print "first position of letter A (case-sensitive) = " _ & InStr(1, TESTSTRING, "A", vbBinaryCompare) Debug.Print "first position of letter A (case-insensitive) = " _ & InStr(1, TESTSTRING, "A", vbTextCompare) Debug.Print "concatenated with & TESTSTRING & "123" End Sub
Rewrite this program in Go while keeping its functionality equivalent to the PowerShell version.
$string = 'alphaBETA' $lower = $string.ToLower() $upper = $string.ToUpper() $title = (Get-Culture).TextInfo.ToTitleCase($string) $lower, $upper, $title
package main import ( "fmt" "strings" "unicode" "unicode/utf8" ) func main() { show("alphaBETA") show("alpha BETA") show("DŽLjnj") show("o'hare O'HARE o’hare don't") } func show(s string) { fmt.Println("\nstring: ", s, " len:", utf8.RuneCountInString(s), "runes") fmt.Println("All upper case: ", strings.ToUpper(s)) fmt.Println("All lower case: ", strings.ToLower(s)) fmt.Println("All title case: ", strings.ToTitle(s)) fmt.Println("Title words: ", strings.Title(s)) fmt.Println("Swapping case: ", strings.Map(unicode.SimpleFold, s)) }
Generate an equivalent C version of this R code.
str <- "alphaBETA" toupper(str) tolower(str)
#include <ctype.h> #include <stdio.h> void str_toupper(char *s) { while(*s) { *s=toupper(*s); s++; } } void str_tolower(char *s) { while(*s) { *s=tolower(*s); s++; } } int main(int argc, char *argv[]) { char t[255]="alphaBETA"; str_toupper(t); printf("uppercase: %s\n", t); str_tolower(t); printf("lowercase: %s\n", t); return 0; }
Port the provided R code into C# while preserving the original functionality.
str <- "alphaBETA" toupper(str) tolower(str)
using System; namespace StringCase { class Program { public static void Main() { String input = scope .("alphaBETA"); input.ToUpper(); Console.WriteLine(input); input.ToLower(); Console.WriteLine(input); } } }
Transform the following R implementation into C++, maintaining the same output and logic.
str <- "alphaBETA" toupper(str) tolower(str)
#include <algorithm> #include <string> #include <cctype> void str_toupper(std::string &str) { std::transform(str.begin(), str.end(), str.begin(), (int(*)(int)) std::toupper); } void str_tolower(std::string &str) { std::transform(str.begin(), str.end(), str.begin(), (int(*)(int)) std::tolower); }
Produce a functionally identical Java code for the snippet given in R.
str <- "alphaBETA" toupper(str) tolower(str)
String str = "alphaBETA"; System.out.println(str.toUpperCase()); System.out.println(str.toLowerCase()); System.out.println("äàâáçñßæεбế".toUpperCase()); System.out.println("ÄÀÂÁÇÑSSÆΕБẾ".toLowerCase());
Maintain the same structure and functionality when rewriting this code in Python.
str <- "alphaBETA" toupper(str) tolower(str)
s = "alphaBETA" print s.upper() print s.lower() print s.swapcase() print "fOo bAR".capitalize() print "fOo bAR".title() import string print string.capwords("fOo bAR")
Convert the following code from R to VB, ensuring the logic remains intact.
str <- "alphaBETA" toupper(str) tolower(str)
Sub Main() Const TESTSTRING As String = "alphaBETA" Debug.Print "initial = " _ & TESTSTRING Debug.Print "uppercase = " _ & UCase(TESTSTRING) Debug.Print "lowercase = " _ & LCase(TESTSTRING) Debug.Print "first letter capitalized = " _ & StrConv(TESTSTRING, vbProperCase) Debug.Print "length (in characters) = " _ & CStr(Len(TESTSTRING)) Debug.Print "length (in bytes) = " _ & CStr(LenB(TESTSTRING)) Debug.Print "reversed = " _ & StrReverse(TESTSTRING) Debug.Print "first position of letter A (case-sensitive) = " _ & InStr(1, TESTSTRING, "A", vbBinaryCompare) Debug.Print "first position of letter A (case-insensitive) = " _ & InStr(1, TESTSTRING, "A", vbTextCompare) Debug.Print "concatenated with & TESTSTRING & "123" End Sub
Change the programming language of this snippet from R to Go without modifying what it does.
str <- "alphaBETA" toupper(str) tolower(str)
package main import ( "fmt" "strings" "unicode" "unicode/utf8" ) func main() { show("alphaBETA") show("alpha BETA") show("DŽLjnj") show("o'hare O'HARE o’hare don't") } func show(s string) { fmt.Println("\nstring: ", s, " len:", utf8.RuneCountInString(s), "runes") fmt.Println("All upper case: ", strings.ToUpper(s)) fmt.Println("All lower case: ", strings.ToLower(s)) fmt.Println("All title case: ", strings.ToTitle(s)) fmt.Println("Title words: ", strings.Title(s)) fmt.Println("Swapping case: ", strings.Map(unicode.SimpleFold, s)) }
Change the following Racket code into C without altering its purpose.
#lang racket (define example "alphaBETA") (string-upcase example) (string-downcase example) (string-titlecase example)
#include <ctype.h> #include <stdio.h> void str_toupper(char *s) { while(*s) { *s=toupper(*s); s++; } } void str_tolower(char *s) { while(*s) { *s=tolower(*s); s++; } } int main(int argc, char *argv[]) { char t[255]="alphaBETA"; str_toupper(t); printf("uppercase: %s\n", t); str_tolower(t); printf("lowercase: %s\n", t); return 0; }
Maintain the same structure and functionality when rewriting this code in C#.
#lang racket (define example "alphaBETA") (string-upcase example) (string-downcase example) (string-titlecase example)
using System; namespace StringCase { class Program { public static void Main() { String input = scope .("alphaBETA"); input.ToUpper(); Console.WriteLine(input); input.ToLower(); Console.WriteLine(input); } } }
Translate the given Racket code snippet into C++ without altering its behavior.
#lang racket (define example "alphaBETA") (string-upcase example) (string-downcase example) (string-titlecase example)
#include <algorithm> #include <string> #include <cctype> void str_toupper(std::string &str) { std::transform(str.begin(), str.end(), str.begin(), (int(*)(int)) std::toupper); } void str_tolower(std::string &str) { std::transform(str.begin(), str.end(), str.begin(), (int(*)(int)) std::tolower); }
Keep all operations the same but rewrite the snippet in Java.
#lang racket (define example "alphaBETA") (string-upcase example) (string-downcase example) (string-titlecase example)
String str = "alphaBETA"; System.out.println(str.toUpperCase()); System.out.println(str.toLowerCase()); System.out.println("äàâáçñßæεбế".toUpperCase()); System.out.println("ÄÀÂÁÇÑSSÆΕБẾ".toLowerCase());
Translate the given Racket code snippet into Python without altering its behavior.
#lang racket (define example "alphaBETA") (string-upcase example) (string-downcase example) (string-titlecase example)
s = "alphaBETA" print s.upper() print s.lower() print s.swapcase() print "fOo bAR".capitalize() print "fOo bAR".title() import string print string.capwords("fOo bAR")
Convert this Racket block to VB, preserving its control flow and logic.
#lang racket (define example "alphaBETA") (string-upcase example) (string-downcase example) (string-titlecase example)
Sub Main() Const TESTSTRING As String = "alphaBETA" Debug.Print "initial = " _ & TESTSTRING Debug.Print "uppercase = " _ & UCase(TESTSTRING) Debug.Print "lowercase = " _ & LCase(TESTSTRING) Debug.Print "first letter capitalized = " _ & StrConv(TESTSTRING, vbProperCase) Debug.Print "length (in characters) = " _ & CStr(Len(TESTSTRING)) Debug.Print "length (in bytes) = " _ & CStr(LenB(TESTSTRING)) Debug.Print "reversed = " _ & StrReverse(TESTSTRING) Debug.Print "first position of letter A (case-sensitive) = " _ & InStr(1, TESTSTRING, "A", vbBinaryCompare) Debug.Print "first position of letter A (case-insensitive) = " _ & InStr(1, TESTSTRING, "A", vbTextCompare) Debug.Print "concatenated with & TESTSTRING & "123" End Sub
Maintain the same structure and functionality when rewriting this code in Go.
#lang racket (define example "alphaBETA") (string-upcase example) (string-downcase example) (string-titlecase example)
package main import ( "fmt" "strings" "unicode" "unicode/utf8" ) func main() { show("alphaBETA") show("alpha BETA") show("DŽLjnj") show("o'hare O'HARE o’hare don't") } func show(s string) { fmt.Println("\nstring: ", s, " len:", utf8.RuneCountInString(s), "runes") fmt.Println("All upper case: ", strings.ToUpper(s)) fmt.Println("All lower case: ", strings.ToLower(s)) fmt.Println("All title case: ", strings.ToTitle(s)) fmt.Println("Title words: ", strings.Title(s)) fmt.Println("Swapping case: ", strings.Map(unicode.SimpleFold, s)) }
Please provide an equivalent version of this COBOL code in C.
IDENTIFICATION DIVISION. PROGRAM-ID. string-case-85. DATA DIVISION. WORKING-STORAGE SECTION. 01 example PIC X(9) VALUE "alphaBETA". 01 result PIC X(9). PROCEDURE DIVISION. DISPLAY "Example: " example DISPLAY "Lower-case: " FUNCTION LOWER-CASE(example) DISPLAY "Upper-case: " FUNCTION UPPER-CASE(example) MOVE example TO result INSPECT result CONVERTING "ABCDEFGHIJKLMNOPQRSTUVWXYZ" TO "abcdefghijklmnopqrstuvwxyz" DISPLAY "Lower-case: " result MOVE example TO result INSPECT result CONVERTING "abcdefghijklmnopqrstuvwxyz" TO "ABCDEFGHIJKLMNOPQRSTUVWXYZ" DISPLAY "Upper-case: " result GOBACK .
#include <ctype.h> #include <stdio.h> void str_toupper(char *s) { while(*s) { *s=toupper(*s); s++; } } void str_tolower(char *s) { while(*s) { *s=tolower(*s); s++; } } int main(int argc, char *argv[]) { char t[255]="alphaBETA"; str_toupper(t); printf("uppercase: %s\n", t); str_tolower(t); printf("lowercase: %s\n", t); return 0; }
Generate an equivalent C# version of this COBOL code.
IDENTIFICATION DIVISION. PROGRAM-ID. string-case-85. DATA DIVISION. WORKING-STORAGE SECTION. 01 example PIC X(9) VALUE "alphaBETA". 01 result PIC X(9). PROCEDURE DIVISION. DISPLAY "Example: " example DISPLAY "Lower-case: " FUNCTION LOWER-CASE(example) DISPLAY "Upper-case: " FUNCTION UPPER-CASE(example) MOVE example TO result INSPECT result CONVERTING "ABCDEFGHIJKLMNOPQRSTUVWXYZ" TO "abcdefghijklmnopqrstuvwxyz" DISPLAY "Lower-case: " result MOVE example TO result INSPECT result CONVERTING "abcdefghijklmnopqrstuvwxyz" TO "ABCDEFGHIJKLMNOPQRSTUVWXYZ" DISPLAY "Upper-case: " result GOBACK .
using System; namespace StringCase { class Program { public static void Main() { String input = scope .("alphaBETA"); input.ToUpper(); Console.WriteLine(input); input.ToLower(); Console.WriteLine(input); } } }
Transform the following COBOL implementation into C++, maintaining the same output and logic.
IDENTIFICATION DIVISION. PROGRAM-ID. string-case-85. DATA DIVISION. WORKING-STORAGE SECTION. 01 example PIC X(9) VALUE "alphaBETA". 01 result PIC X(9). PROCEDURE DIVISION. DISPLAY "Example: " example DISPLAY "Lower-case: " FUNCTION LOWER-CASE(example) DISPLAY "Upper-case: " FUNCTION UPPER-CASE(example) MOVE example TO result INSPECT result CONVERTING "ABCDEFGHIJKLMNOPQRSTUVWXYZ" TO "abcdefghijklmnopqrstuvwxyz" DISPLAY "Lower-case: " result MOVE example TO result INSPECT result CONVERTING "abcdefghijklmnopqrstuvwxyz" TO "ABCDEFGHIJKLMNOPQRSTUVWXYZ" DISPLAY "Upper-case: " result GOBACK .
#include <algorithm> #include <string> #include <cctype> void str_toupper(std::string &str) { std::transform(str.begin(), str.end(), str.begin(), (int(*)(int)) std::toupper); } void str_tolower(std::string &str) { std::transform(str.begin(), str.end(), str.begin(), (int(*)(int)) std::tolower); }
Port the following code from COBOL to Java with equivalent syntax and logic.
IDENTIFICATION DIVISION. PROGRAM-ID. string-case-85. DATA DIVISION. WORKING-STORAGE SECTION. 01 example PIC X(9) VALUE "alphaBETA". 01 result PIC X(9). PROCEDURE DIVISION. DISPLAY "Example: " example DISPLAY "Lower-case: " FUNCTION LOWER-CASE(example) DISPLAY "Upper-case: " FUNCTION UPPER-CASE(example) MOVE example TO result INSPECT result CONVERTING "ABCDEFGHIJKLMNOPQRSTUVWXYZ" TO "abcdefghijklmnopqrstuvwxyz" DISPLAY "Lower-case: " result MOVE example TO result INSPECT result CONVERTING "abcdefghijklmnopqrstuvwxyz" TO "ABCDEFGHIJKLMNOPQRSTUVWXYZ" DISPLAY "Upper-case: " result GOBACK .
String str = "alphaBETA"; System.out.println(str.toUpperCase()); System.out.println(str.toLowerCase()); System.out.println("äàâáçñßæεбế".toUpperCase()); System.out.println("ÄÀÂÁÇÑSSÆΕБẾ".toLowerCase());
Please provide an equivalent version of this COBOL code in Python.
IDENTIFICATION DIVISION. PROGRAM-ID. string-case-85. DATA DIVISION. WORKING-STORAGE SECTION. 01 example PIC X(9) VALUE "alphaBETA". 01 result PIC X(9). PROCEDURE DIVISION. DISPLAY "Example: " example DISPLAY "Lower-case: " FUNCTION LOWER-CASE(example) DISPLAY "Upper-case: " FUNCTION UPPER-CASE(example) MOVE example TO result INSPECT result CONVERTING "ABCDEFGHIJKLMNOPQRSTUVWXYZ" TO "abcdefghijklmnopqrstuvwxyz" DISPLAY "Lower-case: " result MOVE example TO result INSPECT result CONVERTING "abcdefghijklmnopqrstuvwxyz" TO "ABCDEFGHIJKLMNOPQRSTUVWXYZ" DISPLAY "Upper-case: " result GOBACK .
s = "alphaBETA" print s.upper() print s.lower() print s.swapcase() print "fOo bAR".capitalize() print "fOo bAR".title() import string print string.capwords("fOo bAR")
Write the same algorithm in VB as shown in this COBOL implementation.
IDENTIFICATION DIVISION. PROGRAM-ID. string-case-85. DATA DIVISION. WORKING-STORAGE SECTION. 01 example PIC X(9) VALUE "alphaBETA". 01 result PIC X(9). PROCEDURE DIVISION. DISPLAY "Example: " example DISPLAY "Lower-case: " FUNCTION LOWER-CASE(example) DISPLAY "Upper-case: " FUNCTION UPPER-CASE(example) MOVE example TO result INSPECT result CONVERTING "ABCDEFGHIJKLMNOPQRSTUVWXYZ" TO "abcdefghijklmnopqrstuvwxyz" DISPLAY "Lower-case: " result MOVE example TO result INSPECT result CONVERTING "abcdefghijklmnopqrstuvwxyz" TO "ABCDEFGHIJKLMNOPQRSTUVWXYZ" DISPLAY "Upper-case: " result GOBACK .
Sub Main() Const TESTSTRING As String = "alphaBETA" Debug.Print "initial = " _ & TESTSTRING Debug.Print "uppercase = " _ & UCase(TESTSTRING) Debug.Print "lowercase = " _ & LCase(TESTSTRING) Debug.Print "first letter capitalized = " _ & StrConv(TESTSTRING, vbProperCase) Debug.Print "length (in characters) = " _ & CStr(Len(TESTSTRING)) Debug.Print "length (in bytes) = " _ & CStr(LenB(TESTSTRING)) Debug.Print "reversed = " _ & StrReverse(TESTSTRING) Debug.Print "first position of letter A (case-sensitive) = " _ & InStr(1, TESTSTRING, "A", vbBinaryCompare) Debug.Print "first position of letter A (case-insensitive) = " _ & InStr(1, TESTSTRING, "A", vbTextCompare) Debug.Print "concatenated with & TESTSTRING & "123" End Sub
Produce a language-to-language conversion: from COBOL to Go, same semantics.
IDENTIFICATION DIVISION. PROGRAM-ID. string-case-85. DATA DIVISION. WORKING-STORAGE SECTION. 01 example PIC X(9) VALUE "alphaBETA". 01 result PIC X(9). PROCEDURE DIVISION. DISPLAY "Example: " example DISPLAY "Lower-case: " FUNCTION LOWER-CASE(example) DISPLAY "Upper-case: " FUNCTION UPPER-CASE(example) MOVE example TO result INSPECT result CONVERTING "ABCDEFGHIJKLMNOPQRSTUVWXYZ" TO "abcdefghijklmnopqrstuvwxyz" DISPLAY "Lower-case: " result MOVE example TO result INSPECT result CONVERTING "abcdefghijklmnopqrstuvwxyz" TO "ABCDEFGHIJKLMNOPQRSTUVWXYZ" DISPLAY "Upper-case: " result GOBACK .
package main import ( "fmt" "strings" "unicode" "unicode/utf8" ) func main() { show("alphaBETA") show("alpha BETA") show("DŽLjnj") show("o'hare O'HARE o’hare don't") } func show(s string) { fmt.Println("\nstring: ", s, " len:", utf8.RuneCountInString(s), "runes") fmt.Println("All upper case: ", strings.ToUpper(s)) fmt.Println("All lower case: ", strings.ToLower(s)) fmt.Println("All title case: ", strings.ToTitle(s)) fmt.Println("Title words: ", strings.Title(s)) fmt.Println("Swapping case: ", strings.Map(unicode.SimpleFold, s)) }
Port the provided REXX code into C while preserving the original functionality.
options replace format comments java crossref savelog symbols abc = 'alphaBETA' say abc.upper say abc.lower say abc.upper(1, 1) -- capitalize 1st character
#include <ctype.h> #include <stdio.h> void str_toupper(char *s) { while(*s) { *s=toupper(*s); s++; } } void str_tolower(char *s) { while(*s) { *s=tolower(*s); s++; } } int main(int argc, char *argv[]) { char t[255]="alphaBETA"; str_toupper(t); printf("uppercase: %s\n", t); str_tolower(t); printf("lowercase: %s\n", t); return 0; }
Convert this REXX snippet to C# and keep its semantics consistent.
options replace format comments java crossref savelog symbols abc = 'alphaBETA' say abc.upper say abc.lower say abc.upper(1, 1) -- capitalize 1st character
using System; namespace StringCase { class Program { public static void Main() { String input = scope .("alphaBETA"); input.ToUpper(); Console.WriteLine(input); input.ToLower(); Console.WriteLine(input); } } }
Keep all operations the same but rewrite the snippet in C++.
options replace format comments java crossref savelog symbols abc = 'alphaBETA' say abc.upper say abc.lower say abc.upper(1, 1) -- capitalize 1st character
#include <algorithm> #include <string> #include <cctype> void str_toupper(std::string &str) { std::transform(str.begin(), str.end(), str.begin(), (int(*)(int)) std::toupper); } void str_tolower(std::string &str) { std::transform(str.begin(), str.end(), str.begin(), (int(*)(int)) std::tolower); }
Ensure the translated Java code behaves exactly like the original REXX snippet.
options replace format comments java crossref savelog symbols abc = 'alphaBETA' say abc.upper say abc.lower say abc.upper(1, 1) -- capitalize 1st character
String str = "alphaBETA"; System.out.println(str.toUpperCase()); System.out.println(str.toLowerCase()); System.out.println("äàâáçñßæεбế".toUpperCase()); System.out.println("ÄÀÂÁÇÑSSÆΕБẾ".toLowerCase());
Generate an equivalent Python version of this REXX code.
options replace format comments java crossref savelog symbols abc = 'alphaBETA' say abc.upper say abc.lower say abc.upper(1, 1) -- capitalize 1st character
s = "alphaBETA" print s.upper() print s.lower() print s.swapcase() print "fOo bAR".capitalize() print "fOo bAR".title() import string print string.capwords("fOo bAR")
Please provide an equivalent version of this REXX code in VB.
options replace format comments java crossref savelog symbols abc = 'alphaBETA' say abc.upper say abc.lower say abc.upper(1, 1) -- capitalize 1st character
Sub Main() Const TESTSTRING As String = "alphaBETA" Debug.Print "initial = " _ & TESTSTRING Debug.Print "uppercase = " _ & UCase(TESTSTRING) Debug.Print "lowercase = " _ & LCase(TESTSTRING) Debug.Print "first letter capitalized = " _ & StrConv(TESTSTRING, vbProperCase) Debug.Print "length (in characters) = " _ & CStr(Len(TESTSTRING)) Debug.Print "length (in bytes) = " _ & CStr(LenB(TESTSTRING)) Debug.Print "reversed = " _ & StrReverse(TESTSTRING) Debug.Print "first position of letter A (case-sensitive) = " _ & InStr(1, TESTSTRING, "A", vbBinaryCompare) Debug.Print "first position of letter A (case-insensitive) = " _ & InStr(1, TESTSTRING, "A", vbTextCompare) Debug.Print "concatenated with & TESTSTRING & "123" End Sub
Change the programming language of this snippet from REXX to Go without modifying what it does.
options replace format comments java crossref savelog symbols abc = 'alphaBETA' say abc.upper say abc.lower say abc.upper(1, 1) -- capitalize 1st character
package main import ( "fmt" "strings" "unicode" "unicode/utf8" ) func main() { show("alphaBETA") show("alpha BETA") show("DŽLjnj") show("o'hare O'HARE o’hare don't") } func show(s string) { fmt.Println("\nstring: ", s, " len:", utf8.RuneCountInString(s), "runes") fmt.Println("All upper case: ", strings.ToUpper(s)) fmt.Println("All lower case: ", strings.ToLower(s)) fmt.Println("All title case: ", strings.ToTitle(s)) fmt.Println("Title words: ", strings.Title(s)) fmt.Println("Swapping case: ", strings.Map(unicode.SimpleFold, s)) }
Port the following code from Ruby to C with equivalent syntax and logic.
"alphaBETA".downcase "alphaBETA".upcase "alphaBETA".swapcase "alphaBETA".capitalize
#include <ctype.h> #include <stdio.h> void str_toupper(char *s) { while(*s) { *s=toupper(*s); s++; } } void str_tolower(char *s) { while(*s) { *s=tolower(*s); s++; } } int main(int argc, char *argv[]) { char t[255]="alphaBETA"; str_toupper(t); printf("uppercase: %s\n", t); str_tolower(t); printf("lowercase: %s\n", t); return 0; }
Write the same algorithm in C# as shown in this Ruby implementation.
"alphaBETA".downcase "alphaBETA".upcase "alphaBETA".swapcase "alphaBETA".capitalize
using System; namespace StringCase { class Program { public static void Main() { String input = scope .("alphaBETA"); input.ToUpper(); Console.WriteLine(input); input.ToLower(); Console.WriteLine(input); } } }
Convert the following code from Ruby to C++, ensuring the logic remains intact.
"alphaBETA".downcase "alphaBETA".upcase "alphaBETA".swapcase "alphaBETA".capitalize
#include <algorithm> #include <string> #include <cctype> void str_toupper(std::string &str) { std::transform(str.begin(), str.end(), str.begin(), (int(*)(int)) std::toupper); } void str_tolower(std::string &str) { std::transform(str.begin(), str.end(), str.begin(), (int(*)(int)) std::tolower); }
Produce a functionally identical Python code for the snippet given in Ruby.
"alphaBETA".downcase "alphaBETA".upcase "alphaBETA".swapcase "alphaBETA".capitalize
s = "alphaBETA" print s.upper() print s.lower() print s.swapcase() print "fOo bAR".capitalize() print "fOo bAR".title() import string print string.capwords("fOo bAR")
Generate an equivalent VB version of this Ruby code.
"alphaBETA".downcase "alphaBETA".upcase "alphaBETA".swapcase "alphaBETA".capitalize
Sub Main() Const TESTSTRING As String = "alphaBETA" Debug.Print "initial = " _ & TESTSTRING Debug.Print "uppercase = " _ & UCase(TESTSTRING) Debug.Print "lowercase = " _ & LCase(TESTSTRING) Debug.Print "first letter capitalized = " _ & StrConv(TESTSTRING, vbProperCase) Debug.Print "length (in characters) = " _ & CStr(Len(TESTSTRING)) Debug.Print "length (in bytes) = " _ & CStr(LenB(TESTSTRING)) Debug.Print "reversed = " _ & StrReverse(TESTSTRING) Debug.Print "first position of letter A (case-sensitive) = " _ & InStr(1, TESTSTRING, "A", vbBinaryCompare) Debug.Print "first position of letter A (case-insensitive) = " _ & InStr(1, TESTSTRING, "A", vbTextCompare) Debug.Print "concatenated with & TESTSTRING & "123" End Sub
Generate a Go translation of this Ruby snippet without changing its computational steps.
"alphaBETA".downcase "alphaBETA".upcase "alphaBETA".swapcase "alphaBETA".capitalize
package main import ( "fmt" "strings" "unicode" "unicode/utf8" ) func main() { show("alphaBETA") show("alpha BETA") show("DŽLjnj") show("o'hare O'HARE o’hare don't") } func show(s string) { fmt.Println("\nstring: ", s, " len:", utf8.RuneCountInString(s), "runes") fmt.Println("All upper case: ", strings.ToUpper(s)) fmt.Println("All lower case: ", strings.ToLower(s)) fmt.Println("All title case: ", strings.ToTitle(s)) fmt.Println("Title words: ", strings.Title(s)) fmt.Println("Swapping case: ", strings.Map(unicode.SimpleFold, s)) }
Rewrite this program in C while keeping its functionality equivalent to the Scala version.
fun main(args: Array<String>) { val s = "alphaBETA" println(s.toUpperCase()) println(s.toLowerCase()) println(s.capitalize()) println(s.decapitalize()) }
#include <ctype.h> #include <stdio.h> void str_toupper(char *s) { while(*s) { *s=toupper(*s); s++; } } void str_tolower(char *s) { while(*s) { *s=tolower(*s); s++; } } int main(int argc, char *argv[]) { char t[255]="alphaBETA"; str_toupper(t); printf("uppercase: %s\n", t); str_tolower(t); printf("lowercase: %s\n", t); return 0; }
Write a version of this Scala function in C# with identical behavior.
fun main(args: Array<String>) { val s = "alphaBETA" println(s.toUpperCase()) println(s.toLowerCase()) println(s.capitalize()) println(s.decapitalize()) }
using System; namespace StringCase { class Program { public static void Main() { String input = scope .("alphaBETA"); input.ToUpper(); Console.WriteLine(input); input.ToLower(); Console.WriteLine(input); } } }
Write a version of this Scala function in C++ with identical behavior.
fun main(args: Array<String>) { val s = "alphaBETA" println(s.toUpperCase()) println(s.toLowerCase()) println(s.capitalize()) println(s.decapitalize()) }
#include <algorithm> #include <string> #include <cctype> void str_toupper(std::string &str) { std::transform(str.begin(), str.end(), str.begin(), (int(*)(int)) std::toupper); } void str_tolower(std::string &str) { std::transform(str.begin(), str.end(), str.begin(), (int(*)(int)) std::tolower); }
Maintain the same structure and functionality when rewriting this code in Java.
fun main(args: Array<String>) { val s = "alphaBETA" println(s.toUpperCase()) println(s.toLowerCase()) println(s.capitalize()) println(s.decapitalize()) }
String str = "alphaBETA"; System.out.println(str.toUpperCase()); System.out.println(str.toLowerCase()); System.out.println("äàâáçñßæεбế".toUpperCase()); System.out.println("ÄÀÂÁÇÑSSÆΕБẾ".toLowerCase());
Produce a language-to-language conversion: from Scala to Python, same semantics.
fun main(args: Array<String>) { val s = "alphaBETA" println(s.toUpperCase()) println(s.toLowerCase()) println(s.capitalize()) println(s.decapitalize()) }
s = "alphaBETA" print s.upper() print s.lower() print s.swapcase() print "fOo bAR".capitalize() print "fOo bAR".title() import string print string.capwords("fOo bAR")
Transform the following Scala implementation into VB, maintaining the same output and logic.
fun main(args: Array<String>) { val s = "alphaBETA" println(s.toUpperCase()) println(s.toLowerCase()) println(s.capitalize()) println(s.decapitalize()) }
Sub Main() Const TESTSTRING As String = "alphaBETA" Debug.Print "initial = " _ & TESTSTRING Debug.Print "uppercase = " _ & UCase(TESTSTRING) Debug.Print "lowercase = " _ & LCase(TESTSTRING) Debug.Print "first letter capitalized = " _ & StrConv(TESTSTRING, vbProperCase) Debug.Print "length (in characters) = " _ & CStr(Len(TESTSTRING)) Debug.Print "length (in bytes) = " _ & CStr(LenB(TESTSTRING)) Debug.Print "reversed = " _ & StrReverse(TESTSTRING) Debug.Print "first position of letter A (case-sensitive) = " _ & InStr(1, TESTSTRING, "A", vbBinaryCompare) Debug.Print "first position of letter A (case-insensitive) = " _ & InStr(1, TESTSTRING, "A", vbTextCompare) Debug.Print "concatenated with & TESTSTRING & "123" End Sub
Maintain the same structure and functionality when rewriting this code in Go.
fun main(args: Array<String>) { val s = "alphaBETA" println(s.toUpperCase()) println(s.toLowerCase()) println(s.capitalize()) println(s.decapitalize()) }
package main import ( "fmt" "strings" "unicode" "unicode/utf8" ) func main() { show("alphaBETA") show("alpha BETA") show("DŽLjnj") show("o'hare O'HARE o’hare don't") } func show(s string) { fmt.Println("\nstring: ", s, " len:", utf8.RuneCountInString(s), "runes") fmt.Println("All upper case: ", strings.ToUpper(s)) fmt.Println("All lower case: ", strings.ToLower(s)) fmt.Println("All title case: ", strings.ToTitle(s)) fmt.Println("Title words: ", strings.Title(s)) fmt.Println("Swapping case: ", strings.Map(unicode.SimpleFold, s)) }
Write a version of this Swift function in C with identical behavior.
import Foundation println("alphaBETA".uppercaseString) println("alphaBETA".lowercaseString) println("foO BAr".capitalizedString)
#include <ctype.h> #include <stdio.h> void str_toupper(char *s) { while(*s) { *s=toupper(*s); s++; } } void str_tolower(char *s) { while(*s) { *s=tolower(*s); s++; } } int main(int argc, char *argv[]) { char t[255]="alphaBETA"; str_toupper(t); printf("uppercase: %s\n", t); str_tolower(t); printf("lowercase: %s\n", t); return 0; }
Produce a functionally identical C# code for the snippet given in Swift.
import Foundation println("alphaBETA".uppercaseString) println("alphaBETA".lowercaseString) println("foO BAr".capitalizedString)
using System; namespace StringCase { class Program { public static void Main() { String input = scope .("alphaBETA"); input.ToUpper(); Console.WriteLine(input); input.ToLower(); Console.WriteLine(input); } } }
Write the same code in C++ as shown below in Swift.
import Foundation println("alphaBETA".uppercaseString) println("alphaBETA".lowercaseString) println("foO BAr".capitalizedString)
#include <algorithm> #include <string> #include <cctype> void str_toupper(std::string &str) { std::transform(str.begin(), str.end(), str.begin(), (int(*)(int)) std::toupper); } void str_tolower(std::string &str) { std::transform(str.begin(), str.end(), str.begin(), (int(*)(int)) std::tolower); }
Produce a language-to-language conversion: from Swift to Java, same semantics.
import Foundation println("alphaBETA".uppercaseString) println("alphaBETA".lowercaseString) println("foO BAr".capitalizedString)
String str = "alphaBETA"; System.out.println(str.toUpperCase()); System.out.println(str.toLowerCase()); System.out.println("äàâáçñßæεбế".toUpperCase()); System.out.println("ÄÀÂÁÇÑSSÆΕБẾ".toLowerCase());
Produce a language-to-language conversion: from Swift to Python, same semantics.
import Foundation println("alphaBETA".uppercaseString) println("alphaBETA".lowercaseString) println("foO BAr".capitalizedString)
s = "alphaBETA" print s.upper() print s.lower() print s.swapcase() print "fOo bAR".capitalize() print "fOo bAR".title() import string print string.capwords("fOo bAR")
Can you help me rewrite this code in VB instead of Swift, keeping it the same logically?
import Foundation println("alphaBETA".uppercaseString) println("alphaBETA".lowercaseString) println("foO BAr".capitalizedString)
Sub Main() Const TESTSTRING As String = "alphaBETA" Debug.Print "initial = " _ & TESTSTRING Debug.Print "uppercase = " _ & UCase(TESTSTRING) Debug.Print "lowercase = " _ & LCase(TESTSTRING) Debug.Print "first letter capitalized = " _ & StrConv(TESTSTRING, vbProperCase) Debug.Print "length (in characters) = " _ & CStr(Len(TESTSTRING)) Debug.Print "length (in bytes) = " _ & CStr(LenB(TESTSTRING)) Debug.Print "reversed = " _ & StrReverse(TESTSTRING) Debug.Print "first position of letter A (case-sensitive) = " _ & InStr(1, TESTSTRING, "A", vbBinaryCompare) Debug.Print "first position of letter A (case-insensitive) = " _ & InStr(1, TESTSTRING, "A", vbTextCompare) Debug.Print "concatenated with & TESTSTRING & "123" End Sub
Convert this Swift block to Go, preserving its control flow and logic.
import Foundation println("alphaBETA".uppercaseString) println("alphaBETA".lowercaseString) println("foO BAr".capitalizedString)
package main import ( "fmt" "strings" "unicode" "unicode/utf8" ) func main() { show("alphaBETA") show("alpha BETA") show("DŽLjnj") show("o'hare O'HARE o’hare don't") } func show(s string) { fmt.Println("\nstring: ", s, " len:", utf8.RuneCountInString(s), "runes") fmt.Println("All upper case: ", strings.ToUpper(s)) fmt.Println("All lower case: ", strings.ToLower(s)) fmt.Println("All title case: ", strings.ToTitle(s)) fmt.Println("Title words: ", strings.Title(s)) fmt.Println("Swapping case: ", strings.Map(unicode.SimpleFold, s)) }
Rewrite the snippet below in C so it works the same as the original Tcl code.
set string alphaBETA string toupper $string ; string tolower $string ; string totitle $string ; proc swapcase {s} { foreach char [split $s ""] { if {$char eq [set CHAR [string toupper $char]]} { append new [string tolower $char] } else { append new $CHAR } } return $new } swapcase $string ; proc swapcase_en {s} { string map { a A b B c C d D e E f F g G h H i I j J k K l L m M n N o O p P q Q r R s S t T u U v V w W x X y Y z Z A a B b C c D d E e F f G g H h I i J j K k L l M m N n O o P p Q q R r S s T t U u V v W w X x Y y Z z } $s } swapcase Père ; swapcase_en Père ;
#include <ctype.h> #include <stdio.h> void str_toupper(char *s) { while(*s) { *s=toupper(*s); s++; } } void str_tolower(char *s) { while(*s) { *s=tolower(*s); s++; } } int main(int argc, char *argv[]) { char t[255]="alphaBETA"; str_toupper(t); printf("uppercase: %s\n", t); str_tolower(t); printf("lowercase: %s\n", t); return 0; }
Convert this Tcl snippet to C# and keep its semantics consistent.
set string alphaBETA string toupper $string ; string tolower $string ; string totitle $string ; proc swapcase {s} { foreach char [split $s ""] { if {$char eq [set CHAR [string toupper $char]]} { append new [string tolower $char] } else { append new $CHAR } } return $new } swapcase $string ; proc swapcase_en {s} { string map { a A b B c C d D e E f F g G h H i I j J k K l L m M n N o O p P q Q r R s S t T u U v V w W x X y Y z Z A a B b C c D d E e F f G g H h I i J j K k L l M m N n O o P p Q q R r S s T t U u V v W w X x Y y Z z } $s } swapcase Père ; swapcase_en Père ;
using System; namespace StringCase { class Program { public static void Main() { String input = scope .("alphaBETA"); input.ToUpper(); Console.WriteLine(input); input.ToLower(); Console.WriteLine(input); } } }
Ensure the translated C++ code behaves exactly like the original Tcl snippet.
set string alphaBETA string toupper $string ; string tolower $string ; string totitle $string ; proc swapcase {s} { foreach char [split $s ""] { if {$char eq [set CHAR [string toupper $char]]} { append new [string tolower $char] } else { append new $CHAR } } return $new } swapcase $string ; proc swapcase_en {s} { string map { a A b B c C d D e E f F g G h H i I j J k K l L m M n N o O p P q Q r R s S t T u U v V w W x X y Y z Z A a B b C c D d E e F f G g H h I i J j K k L l M m N n O o P p Q q R r S s T t U u V v W w X x Y y Z z } $s } swapcase Père ; swapcase_en Père ;
#include <algorithm> #include <string> #include <cctype> void str_toupper(std::string &str) { std::transform(str.begin(), str.end(), str.begin(), (int(*)(int)) std::toupper); } void str_tolower(std::string &str) { std::transform(str.begin(), str.end(), str.begin(), (int(*)(int)) std::tolower); }
Produce a language-to-language conversion: from Tcl to Java, same semantics.
set string alphaBETA string toupper $string ; string tolower $string ; string totitle $string ; proc swapcase {s} { foreach char [split $s ""] { if {$char eq [set CHAR [string toupper $char]]} { append new [string tolower $char] } else { append new $CHAR } } return $new } swapcase $string ; proc swapcase_en {s} { string map { a A b B c C d D e E f F g G h H i I j J k K l L m M n N o O p P q Q r R s S t T u U v V w W x X y Y z Z A a B b C c D d E e F f G g H h I i J j K k L l M m N n O o P p Q q R r S s T t U u V v W w X x Y y Z z } $s } swapcase Père ; swapcase_en Père ;
String str = "alphaBETA"; System.out.println(str.toUpperCase()); System.out.println(str.toLowerCase()); System.out.println("äàâáçñßæεбế".toUpperCase()); System.out.println("ÄÀÂÁÇÑSSÆΕБẾ".toLowerCase());
Port the following code from Tcl to Python with equivalent syntax and logic.
set string alphaBETA string toupper $string ; string tolower $string ; string totitle $string ; proc swapcase {s} { foreach char [split $s ""] { if {$char eq [set CHAR [string toupper $char]]} { append new [string tolower $char] } else { append new $CHAR } } return $new } swapcase $string ; proc swapcase_en {s} { string map { a A b B c C d D e E f F g G h H i I j J k K l L m M n N o O p P q Q r R s S t T u U v V w W x X y Y z Z A a B b C c D d E e F f G g H h I i J j K k L l M m N n O o P p Q q R r S s T t U u V v W w X x Y y Z z } $s } swapcase Père ; swapcase_en Père ;
s = "alphaBETA" print s.upper() print s.lower() print s.swapcase() print "fOo bAR".capitalize() print "fOo bAR".title() import string print string.capwords("fOo bAR")
Translate this program into VB but keep the logic exactly as in Tcl.
set string alphaBETA string toupper $string ; string tolower $string ; string totitle $string ; proc swapcase {s} { foreach char [split $s ""] { if {$char eq [set CHAR [string toupper $char]]} { append new [string tolower $char] } else { append new $CHAR } } return $new } swapcase $string ; proc swapcase_en {s} { string map { a A b B c C d D e E f F g G h H i I j J k K l L m M n N o O p P q Q r R s S t T u U v V w W x X y Y z Z A a B b C c D d E e F f G g H h I i J j K k L l M m N n O o P p Q q R r S s T t U u V v W w X x Y y Z z } $s } swapcase Père ; swapcase_en Père ;
Sub Main() Const TESTSTRING As String = "alphaBETA" Debug.Print "initial = " _ & TESTSTRING Debug.Print "uppercase = " _ & UCase(TESTSTRING) Debug.Print "lowercase = " _ & LCase(TESTSTRING) Debug.Print "first letter capitalized = " _ & StrConv(TESTSTRING, vbProperCase) Debug.Print "length (in characters) = " _ & CStr(Len(TESTSTRING)) Debug.Print "length (in bytes) = " _ & CStr(LenB(TESTSTRING)) Debug.Print "reversed = " _ & StrReverse(TESTSTRING) Debug.Print "first position of letter A (case-sensitive) = " _ & InStr(1, TESTSTRING, "A", vbBinaryCompare) Debug.Print "first position of letter A (case-insensitive) = " _ & InStr(1, TESTSTRING, "A", vbTextCompare) Debug.Print "concatenated with & TESTSTRING & "123" End Sub
Can you help me rewrite this code in Go instead of Tcl, keeping it the same logically?
set string alphaBETA string toupper $string ; string tolower $string ; string totitle $string ; proc swapcase {s} { foreach char [split $s ""] { if {$char eq [set CHAR [string toupper $char]]} { append new [string tolower $char] } else { append new $CHAR } } return $new } swapcase $string ; proc swapcase_en {s} { string map { a A b B c C d D e E f F g G h H i I j J k K l L m M n N o O p P q Q r R s S t T u U v V w W x X y Y z Z A a B b C c D d E e F f G g H h I i J j K k L l M m N n O o P p Q q R r S s T t U u V v W w X x Y y Z z } $s } swapcase Père ; swapcase_en Père ;
package main import ( "fmt" "strings" "unicode" "unicode/utf8" ) func main() { show("alphaBETA") show("alpha BETA") show("DŽLjnj") show("o'hare O'HARE o’hare don't") } func show(s string) { fmt.Println("\nstring: ", s, " len:", utf8.RuneCountInString(s), "runes") fmt.Println("All upper case: ", strings.ToUpper(s)) fmt.Println("All lower case: ", strings.ToLower(s)) fmt.Println("All title case: ", strings.ToTitle(s)) fmt.Println("Title words: ", strings.Title(s)) fmt.Println("Swapping case: ", strings.Map(unicode.SimpleFold, s)) }
Transform the following Rust implementation into PHP, maintaining the same output and logic.
fn main() { println!("{}", "jalapeño".to_uppercase()); println!("{}", "JALAPEÑO".to_lowercase()); }
$str = "alphaBETA"; echo strtoupper($str), "\n"; // ALPHABETA echo strtolower($str), "\n"; // alphabeta echo ucfirst($str), "\n"; // AlphaBETA echo lcfirst("FOObar"), "\n"; // fOObar echo ucwords("foO baR baZ"), "\n"; // FoO BaR BaZ echo lcwords("FOo BAr BAz"), "\n"; // fOo bAr bAz
Change the programming language of this snippet from Ada to PHP without modifying what it does.
with Ada.Characters.Handling, Ada.Text_IO; use Ada.Characters.Handling, Ada.Text_IO; procedure Upper_Case_String is S : constant String := "alphaBETA"; begin Put_Line (To_Upper (S)); Put_Line (To_Lower (S)); end Upper_Case_String;
$str = "alphaBETA"; echo strtoupper($str), "\n"; // ALPHABETA echo strtolower($str), "\n"; // alphabeta echo ucfirst($str), "\n"; // AlphaBETA echo lcfirst("FOObar"), "\n"; // fOObar echo ucwords("foO baR baZ"), "\n"; // FoO BaR BaZ echo lcwords("FOo BAr BAz"), "\n"; // fOo bAr bAz
Translate this program into PHP but keep the logic exactly as in Arturo.
str: "alphaBETA" print ["uppercase  :" upper str] print ["lowercase  :" lower str] print ["capitalize :" capitalize str]
$str = "alphaBETA"; echo strtoupper($str), "\n"; // ALPHABETA echo strtolower($str), "\n"; // alphabeta echo ucfirst($str), "\n"; // AlphaBETA echo lcfirst("FOObar"), "\n"; // fOObar echo ucwords("foO baR baZ"), "\n"; // FoO BaR BaZ echo lcwords("FOo BAr BAz"), "\n"; // fOo bAr bAz
Can you help me rewrite this code in PHP instead of AutoHotKey, keeping it the same logically?
a := "alphaBETA" StringLower, b, a  StringUpper, c, a  StringUpper, d, a, T 
$str = "alphaBETA"; echo strtoupper($str), "\n"; // ALPHABETA echo strtolower($str), "\n"; // alphabeta echo ucfirst($str), "\n"; // AlphaBETA echo lcfirst("FOObar"), "\n"; // fOObar echo ucwords("foO baR baZ"), "\n"; // FoO BaR BaZ echo lcwords("FOo BAr BAz"), "\n"; // fOo bAr bAz
Convert this AWK snippet to PHP and keep its semantics consistent.
BEGIN { a = "alphaBETA"; print toupper(a), tolower(a) }
$str = "alphaBETA"; echo strtoupper($str), "\n"; // ALPHABETA echo strtolower($str), "\n"; // alphabeta echo ucfirst($str), "\n"; // AlphaBETA echo lcfirst("FOObar"), "\n"; // fOObar echo ucwords("foO baR baZ"), "\n"; // FoO BaR BaZ echo lcwords("FOo BAr BAz"), "\n"; // fOo bAr bAz
Keep all operations the same but rewrite the snippet in PHP.
INSTALL @lib$+"STRINGLIB" original$ = "alphaBETA" PRINT "Original: " original$ PRINT "Lower case: " FN_lower(original$) PRINT "Upper case: " FN_upper(original$) PRINT "Title case: " FN_title(original$)
$str = "alphaBETA"; echo strtoupper($str), "\n"; // ALPHABETA echo strtolower($str), "\n"; // alphabeta echo ucfirst($str), "\n"; // AlphaBETA echo lcfirst("FOObar"), "\n"; // fOObar echo ucwords("foO baR baZ"), "\n"; // FoO BaR BaZ echo lcwords("FOo BAr BAz"), "\n"; // fOo bAr bAz
Port the provided Common_Lisp code into PHP while preserving the original functionality.
(def string "alphaBETA") (println (.toUpperCase string)) (println (.toLowerCase string))
$str = "alphaBETA"; echo strtoupper($str), "\n"; // ALPHABETA echo strtolower($str), "\n"; // alphabeta echo ucfirst($str), "\n"; // AlphaBETA echo lcfirst("FOObar"), "\n"; // fOObar echo ucwords("foO baR baZ"), "\n"; // FoO BaR BaZ echo lcwords("FOo BAr BAz"), "\n"; // fOo bAr bAz
Write the same algorithm in PHP as shown in this D implementation.
void main() { import std.stdio, std.string; immutable s = "alphaBETA"; s.toUpper.writeln; s.toLower.writeln; }
$str = "alphaBETA"; echo strtoupper($str), "\n"; // ALPHABETA echo strtolower($str), "\n"; // alphabeta echo ucfirst($str), "\n"; // AlphaBETA echo lcfirst("FOObar"), "\n"; // fOObar echo ucwords("foO baR baZ"), "\n"; // FoO BaR BaZ echo lcwords("FOo BAr BAz"), "\n"; // fOo bAr bAz
Change the programming language of this snippet from Delphi to PHP without modifying what it does.
PrintLn(UpperCase('alphaBETA')); PrintLn(LowerCase('alphaBETA'));
$str = "alphaBETA"; echo strtoupper($str), "\n"; // ALPHABETA echo strtolower($str), "\n"; // alphabeta echo ucfirst($str), "\n"; // AlphaBETA echo lcfirst("FOObar"), "\n"; // fOObar echo ucwords("foO baR baZ"), "\n"; // FoO BaR BaZ echo lcwords("FOo BAr BAz"), "\n"; // fOo bAr bAz
Produce a functionally identical PHP code for the snippet given in Elixir.
String.downcase("alphaBETA") String.upcase("alphaBETA") String.capitalize("alphaBETA")
$str = "alphaBETA"; echo strtoupper($str), "\n"; // ALPHABETA echo strtolower($str), "\n"; // alphabeta echo ucfirst($str), "\n"; // AlphaBETA echo lcfirst("FOObar"), "\n"; // fOObar echo ucwords("foO baR baZ"), "\n"; // FoO BaR BaZ echo lcwords("FOo BAr BAz"), "\n"; // fOo bAr bAz
Transform the following Erlang implementation into PHP, maintaining the same output and logic.
string:to_upper("alphaBETA"). string:to_lower("alphaBETA").
$str = "alphaBETA"; echo strtoupper($str), "\n"; // ALPHABETA echo strtolower($str), "\n"; // alphabeta echo ucfirst($str), "\n"; // AlphaBETA echo lcfirst("FOObar"), "\n"; // fOObar echo ucwords("foO baR baZ"), "\n"; // FoO BaR BaZ echo lcwords("FOo BAr BAz"), "\n"; // fOo bAr bAz
Port the provided F# code into PHP while preserving the original functionality.
let s = "alphaBETA" let upper = s.ToUpper() let lower = s.ToLower()
$str = "alphaBETA"; echo strtoupper($str), "\n"; // ALPHABETA echo strtolower($str), "\n"; // alphabeta echo ucfirst($str), "\n"; // AlphaBETA echo lcfirst("FOObar"), "\n"; // fOObar echo ucwords("foO baR baZ"), "\n"; // FoO BaR BaZ echo lcwords("FOo BAr BAz"), "\n"; // fOo bAr bAz
Write the same algorithm in PHP as shown in this Factor implementation.
"alphaBETA" >lower "alphaBETA" >upper "alphaBETA" >title "ß" >case-fold
$str = "alphaBETA"; echo strtoupper($str), "\n"; // ALPHABETA echo strtolower($str), "\n"; // alphabeta echo ucfirst($str), "\n"; // AlphaBETA echo lcfirst("FOObar"), "\n"; // fOObar echo ucwords("foO baR baZ"), "\n"; // FoO BaR BaZ echo lcwords("FOo BAr BAz"), "\n"; // fOo bAr bAz
Convert this Fortran snippet to PHP and keep its semantics consistent.
program example implicit none character(9) :: teststring = "alphaBETA" call To_upper(teststring) write(*,*) teststring call To_lower(teststring) write(*,*) teststring contains subroutine To_upper(str) character(*), intent(in out) :: str integer :: i do i = 1, len(str) select case(str(i:i)) case("a":"z") str(i:i) = achar(iachar(str(i:i))-32) end select end do end subroutine To_upper subroutine To_lower(str) character(*), intent(in out) :: str integer :: i do i = 1, len(str) select case(str(i:i)) case("A":"Z") str(i:i) = achar(iachar(str(i:i))+32) end select end do end subroutine To_Lower end program example
$str = "alphaBETA"; echo strtoupper($str), "\n"; // ALPHABETA echo strtolower($str), "\n"; // alphabeta echo ucfirst($str), "\n"; // AlphaBETA echo lcfirst("FOObar"), "\n"; // fOObar echo ucwords("foO baR baZ"), "\n"; // FoO BaR BaZ echo lcwords("FOo BAr BAz"), "\n"; // fOo bAr bAz
Write a version of this Groovy function in PHP with identical behavior.
def str = 'alphaBETA' println str.toUpperCase() println str.toLowerCase()
$str = "alphaBETA"; echo strtoupper($str), "\n"; // ALPHABETA echo strtolower($str), "\n"; // alphabeta echo ucfirst($str), "\n"; // AlphaBETA echo lcfirst("FOObar"), "\n"; // fOObar echo ucwords("foO baR baZ"), "\n"; // FoO BaR BaZ echo lcwords("FOo BAr BAz"), "\n"; // fOo bAr bAz
Generate an equivalent PHP version of this Haskell code.
import Data.Char s = "alphaBETA" lower = map toLower s upper = map toUpper s
$str = "alphaBETA"; echo strtoupper($str), "\n"; // ALPHABETA echo strtolower($str), "\n"; // alphabeta echo ucfirst($str), "\n"; // AlphaBETA echo lcfirst("FOObar"), "\n"; // fOObar echo ucwords("foO baR baZ"), "\n"; // FoO BaR BaZ echo lcwords("FOo BAr BAz"), "\n"; // fOo bAr bAz
Generate a PHP translation of this Icon snippet without changing its computational steps.
procedure main() write(map("alphaBETA")) write(map("alphaBETA",&lcase,&ucase)) end
$str = "alphaBETA"; echo strtoupper($str), "\n"; // ALPHABETA echo strtolower($str), "\n"; // alphabeta echo ucfirst($str), "\n"; // AlphaBETA echo lcfirst("FOObar"), "\n"; // fOObar echo ucwords("foO baR baZ"), "\n"; // FoO BaR BaZ echo lcwords("FOo BAr BAz"), "\n"; // fOo bAr bAz
Generate an equivalent PHP version of this J code.
toupper 'alphaBETA' ALPHABETA tolower 'alphaBETA' alphabeta
$str = "alphaBETA"; echo strtoupper($str), "\n"; // ALPHABETA echo strtolower($str), "\n"; // alphabeta echo ucfirst($str), "\n"; // AlphaBETA echo lcfirst("FOObar"), "\n"; // fOObar echo ucwords("foO baR baZ"), "\n"; // FoO BaR BaZ echo lcwords("FOo BAr BAz"), "\n"; // fOo bAr bAz
Write a version of this Julia function in PHP with identical behavior.
julia> uppercase("alphaBETA") "ALPHABETA" julia> lowercase("alphaBETA") "alphabeta"
$str = "alphaBETA"; echo strtoupper($str), "\n"; // ALPHABETA echo strtolower($str), "\n"; // alphabeta echo ucfirst($str), "\n"; // AlphaBETA echo lcfirst("FOObar"), "\n"; // fOObar echo ucwords("foO baR baZ"), "\n"; // FoO BaR BaZ echo lcwords("FOo BAr BAz"), "\n"; // fOo bAr bAz
Write the same algorithm in PHP as shown in this Lua implementation.
str = "alphaBETA" print( string.upper(str) ) print( string.lower(str) ) print ( str:upper() ) print ( str:lower() )
$str = "alphaBETA"; echo strtoupper($str), "\n"; // ALPHABETA echo strtolower($str), "\n"; // alphabeta echo ucfirst($str), "\n"; // AlphaBETA echo lcfirst("FOObar"), "\n"; // fOObar echo ucwords("foO baR baZ"), "\n"; // FoO BaR BaZ echo lcwords("FOo BAr BAz"), "\n"; // fOo bAr bAz
Produce a functionally identical PHP code for the snippet given in Mathematica.
str="alphaBETA"; ToUpperCase[str] ToLowerCase[str]
$str = "alphaBETA"; echo strtoupper($str), "\n"; // ALPHABETA echo strtolower($str), "\n"; // alphabeta echo ucfirst($str), "\n"; // AlphaBETA echo lcfirst("FOObar"), "\n"; // fOObar echo ucwords("foO baR baZ"), "\n"; // FoO BaR BaZ echo lcwords("FOo BAr BAz"), "\n"; // fOo bAr bAz
Translate the given MATLAB code snippet into PHP without altering its behavior.
>> upper('alphaBETA') ans = ALPHABETA >> lower('alphaBETA') ans = alphabeta
$str = "alphaBETA"; echo strtoupper($str), "\n"; // ALPHABETA echo strtolower($str), "\n"; // alphabeta echo ucfirst($str), "\n"; // AlphaBETA echo lcfirst("FOObar"), "\n"; // fOObar echo ucwords("foO baR baZ"), "\n"; // FoO BaR BaZ echo lcwords("FOo BAr BAz"), "\n"; // fOo bAr bAz
Ensure the translated PHP code behaves exactly like the original Nim snippet.
import strutils var s: string = "alphaBETA_123" echo s, " as upper case: ", toUpperAscii(s) echo s, " as lower case: ", toLowerAscii(s) echo s, " as capitalized: ", capitalizeAscii(s) echo s, " as normal case: ", normalize(s)
$str = "alphaBETA"; echo strtoupper($str), "\n"; // ALPHABETA echo strtolower($str), "\n"; // alphabeta echo ucfirst($str), "\n"; // AlphaBETA echo lcfirst("FOObar"), "\n"; // fOObar echo ucwords("foO baR baZ"), "\n"; // FoO BaR BaZ echo lcwords("FOo BAr BAz"), "\n"; // fOo bAr bAz
Port the following code from OCaml to PHP with equivalent syntax and logic.
let () = let str = "alphaBETA" in print_endline (String.uppercase_ascii str); print_endline (String.lowercase_ascii str); print_endline (String.capitalize_ascii str); ;;
$str = "alphaBETA"; echo strtoupper($str), "\n"; // ALPHABETA echo strtolower($str), "\n"; // alphabeta echo ucfirst($str), "\n"; // AlphaBETA echo lcfirst("FOObar"), "\n"; // fOObar echo ucwords("foO baR baZ"), "\n"; // FoO BaR BaZ echo lcwords("FOo BAr BAz"), "\n"; // fOo bAr bAz
Port the provided Pascal code into PHP while preserving the original functionality.
writeln(uppercase('alphaBETA')); writeln(lowercase('alphaBETA'));
$str = "alphaBETA"; echo strtoupper($str), "\n"; // ALPHABETA echo strtolower($str), "\n"; // alphabeta echo ucfirst($str), "\n"; // AlphaBETA echo lcfirst("FOObar"), "\n"; // fOObar echo ucwords("foO baR baZ"), "\n"; // FoO BaR BaZ echo lcwords("FOo BAr BAz"), "\n"; // fOo bAr bAz
Preserve the algorithm and functionality while converting the code from Perl to PHP.
my $string = "alphaBETA"; print uc($string), "\n"; print lc($string), "\n"; $string =~ tr/[a-z][A-Z]/[A-Z][a-z]/; print "$string\n"; print ucfirst($string), "\n"; print lcfirst("FOObar"), "\n";
$str = "alphaBETA"; echo strtoupper($str), "\n"; // ALPHABETA echo strtolower($str), "\n"; // alphabeta echo ucfirst($str), "\n"; // AlphaBETA echo lcfirst("FOObar"), "\n"; // fOObar echo ucwords("foO baR baZ"), "\n"; // FoO BaR BaZ echo lcwords("FOo BAr BAz"), "\n"; // fOo bAr bAz
Generate a PHP translation of this PowerShell snippet without changing its computational steps.
$string = 'alphaBETA' $lower = $string.ToLower() $upper = $string.ToUpper() $title = (Get-Culture).TextInfo.ToTitleCase($string) $lower, $upper, $title
$str = "alphaBETA"; echo strtoupper($str), "\n"; // ALPHABETA echo strtolower($str), "\n"; // alphabeta echo ucfirst($str), "\n"; // AlphaBETA echo lcfirst("FOObar"), "\n"; // fOObar echo ucwords("foO baR baZ"), "\n"; // FoO BaR BaZ echo lcwords("FOo BAr BAz"), "\n"; // fOo bAr bAz
Can you help me rewrite this code in PHP instead of R, keeping it the same logically?
str <- "alphaBETA" toupper(str) tolower(str)
$str = "alphaBETA"; echo strtoupper($str), "\n"; // ALPHABETA echo strtolower($str), "\n"; // alphabeta echo ucfirst($str), "\n"; // AlphaBETA echo lcfirst("FOObar"), "\n"; // fOObar echo ucwords("foO baR baZ"), "\n"; // FoO BaR BaZ echo lcwords("FOo BAr BAz"), "\n"; // fOo bAr bAz
Write the same code in PHP as shown below in Racket.
#lang racket (define example "alphaBETA") (string-upcase example) (string-downcase example) (string-titlecase example)
$str = "alphaBETA"; echo strtoupper($str), "\n"; // ALPHABETA echo strtolower($str), "\n"; // alphabeta echo ucfirst($str), "\n"; // AlphaBETA echo lcfirst("FOObar"), "\n"; // fOObar echo ucwords("foO baR baZ"), "\n"; // FoO BaR BaZ echo lcwords("FOo BAr BAz"), "\n"; // fOo bAr bAz
Change the programming language of this snippet from COBOL to PHP without modifying what it does.
IDENTIFICATION DIVISION. PROGRAM-ID. string-case-85. DATA DIVISION. WORKING-STORAGE SECTION. 01 example PIC X(9) VALUE "alphaBETA". 01 result PIC X(9). PROCEDURE DIVISION. DISPLAY "Example: " example DISPLAY "Lower-case: " FUNCTION LOWER-CASE(example) DISPLAY "Upper-case: " FUNCTION UPPER-CASE(example) MOVE example TO result INSPECT result CONVERTING "ABCDEFGHIJKLMNOPQRSTUVWXYZ" TO "abcdefghijklmnopqrstuvwxyz" DISPLAY "Lower-case: " result MOVE example TO result INSPECT result CONVERTING "abcdefghijklmnopqrstuvwxyz" TO "ABCDEFGHIJKLMNOPQRSTUVWXYZ" DISPLAY "Upper-case: " result GOBACK .
$str = "alphaBETA"; echo strtoupper($str), "\n"; // ALPHABETA echo strtolower($str), "\n"; // alphabeta echo ucfirst($str), "\n"; // AlphaBETA echo lcfirst("FOObar"), "\n"; // fOObar echo ucwords("foO baR baZ"), "\n"; // FoO BaR BaZ echo lcwords("FOo BAr BAz"), "\n"; // fOo bAr bAz
Generate a PHP translation of this REXX snippet without changing its computational steps.
options replace format comments java crossref savelog symbols abc = 'alphaBETA' say abc.upper say abc.lower say abc.upper(1, 1) -- capitalize 1st character
$str = "alphaBETA"; echo strtoupper($str), "\n"; // ALPHABETA echo strtolower($str), "\n"; // alphabeta echo ucfirst($str), "\n"; // AlphaBETA echo lcfirst("FOObar"), "\n"; // fOObar echo ucwords("foO baR baZ"), "\n"; // FoO BaR BaZ echo lcwords("FOo BAr BAz"), "\n"; // fOo bAr bAz
Keep all operations the same but rewrite the snippet in PHP.
"alphaBETA".downcase "alphaBETA".upcase "alphaBETA".swapcase "alphaBETA".capitalize
$str = "alphaBETA"; echo strtoupper($str), "\n"; // ALPHABETA echo strtolower($str), "\n"; // alphabeta echo ucfirst($str), "\n"; // AlphaBETA echo lcfirst("FOObar"), "\n"; // fOObar echo ucwords("foO baR baZ"), "\n"; // FoO BaR BaZ echo lcwords("FOo BAr BAz"), "\n"; // fOo bAr bAz
Convert the following code from Scala to PHP, ensuring the logic remains intact.
fun main(args: Array<String>) { val s = "alphaBETA" println(s.toUpperCase()) println(s.toLowerCase()) println(s.capitalize()) println(s.decapitalize()) }
$str = "alphaBETA"; echo strtoupper($str), "\n"; // ALPHABETA echo strtolower($str), "\n"; // alphabeta echo ucfirst($str), "\n"; // AlphaBETA echo lcfirst("FOObar"), "\n"; // fOObar echo ucwords("foO baR baZ"), "\n"; // FoO BaR BaZ echo lcwords("FOo BAr BAz"), "\n"; // fOo bAr bAz
Generate an equivalent PHP version of this Swift code.
import Foundation println("alphaBETA".uppercaseString) println("alphaBETA".lowercaseString) println("foO BAr".capitalizedString)
$str = "alphaBETA"; echo strtoupper($str), "\n"; // ALPHABETA echo strtolower($str), "\n"; // alphabeta echo ucfirst($str), "\n"; // AlphaBETA echo lcfirst("FOObar"), "\n"; // fOObar echo ucwords("foO baR baZ"), "\n"; // FoO BaR BaZ echo lcwords("FOo BAr BAz"), "\n"; // fOo bAr bAz
Generate a PHP translation of this Tcl snippet without changing its computational steps.
set string alphaBETA string toupper $string ; string tolower $string ; string totitle $string ; proc swapcase {s} { foreach char [split $s ""] { if {$char eq [set CHAR [string toupper $char]]} { append new [string tolower $char] } else { append new $CHAR } } return $new } swapcase $string ; proc swapcase_en {s} { string map { a A b B c C d D e E f F g G h H i I j J k K l L m M n N o O p P q Q r R s S t T u U v V w W x X y Y z Z A a B b C c D d E e F f G g H h I i J j K k L l M m N n O o P p Q q R r S s T t U u V v W w X x Y y Z z } $s } swapcase Père ; swapcase_en Père ;
$str = "alphaBETA"; echo strtoupper($str), "\n"; // ALPHABETA echo strtolower($str), "\n"; // alphabeta echo ucfirst($str), "\n"; // AlphaBETA echo lcfirst("FOObar"), "\n"; // fOObar echo ucwords("foO baR baZ"), "\n"; // FoO BaR BaZ echo lcwords("FOo BAr BAz"), "\n"; // fOo bAr bAz
Write the same code in Rust as shown below in C.
#include <ctype.h> #include <stdio.h> void str_toupper(char *s) { while(*s) { *s=toupper(*s); s++; } } void str_tolower(char *s) { while(*s) { *s=tolower(*s); s++; } } int main(int argc, char *argv[]) { char t[255]="alphaBETA"; str_toupper(t); printf("uppercase: %s\n", t); str_tolower(t); printf("lowercase: %s\n", t); return 0; }
fn main() { println!("{}", "jalapeño".to_uppercase()); println!("{}", "JALAPEÑO".to_lowercase()); }
Please provide an equivalent version of this C++ code in Rust.
#include <algorithm> #include <string> #include <cctype> void str_toupper(std::string &str) { std::transform(str.begin(), str.end(), str.begin(), (int(*)(int)) std::toupper); } void str_tolower(std::string &str) { std::transform(str.begin(), str.end(), str.begin(), (int(*)(int)) std::tolower); }
fn main() { println!("{}", "jalapeño".to_uppercase()); println!("{}", "JALAPEÑO".to_lowercase()); }
Write the same algorithm in Rust as shown in this C# implementation.
using System; namespace StringCase { class Program { public static void Main() { String input = scope .("alphaBETA"); input.ToUpper(); Console.WriteLine(input); input.ToLower(); Console.WriteLine(input); } } }
fn main() { println!("{}", "jalapeño".to_uppercase()); println!("{}", "JALAPEÑO".to_lowercase()); }
Convert this Go block to Rust, preserving its control flow and logic.
package main import ( "fmt" "strings" "unicode" "unicode/utf8" ) func main() { show("alphaBETA") show("alpha BETA") show("DŽLjnj") show("o'hare O'HARE o’hare don't") } func show(s string) { fmt.Println("\nstring: ", s, " len:", utf8.RuneCountInString(s), "runes") fmt.Println("All upper case: ", strings.ToUpper(s)) fmt.Println("All lower case: ", strings.ToLower(s)) fmt.Println("All title case: ", strings.ToTitle(s)) fmt.Println("Title words: ", strings.Title(s)) fmt.Println("Swapping case: ", strings.Map(unicode.SimpleFold, s)) }
fn main() { println!("{}", "jalapeño".to_uppercase()); println!("{}", "JALAPEÑO".to_lowercase()); }
Generate an equivalent Python version of this Rust code.
fn main() { println!("{}", "jalapeño".to_uppercase()); println!("{}", "JALAPEÑO".to_lowercase()); }
s = "alphaBETA" print s.upper() print s.lower() print s.swapcase() print "fOo bAR".capitalize() print "fOo bAR".title() import string print string.capwords("fOo bAR")
Rewrite this program in VB while keeping its functionality equivalent to the Rust version.
fn main() { println!("{}", "jalapeño".to_uppercase()); println!("{}", "JALAPEÑO".to_lowercase()); }
Sub Main() Const TESTSTRING As String = "alphaBETA" Debug.Print "initial = " _ & TESTSTRING Debug.Print "uppercase = " _ & UCase(TESTSTRING) Debug.Print "lowercase = " _ & LCase(TESTSTRING) Debug.Print "first letter capitalized = " _ & StrConv(TESTSTRING, vbProperCase) Debug.Print "length (in characters) = " _ & CStr(Len(TESTSTRING)) Debug.Print "length (in bytes) = " _ & CStr(LenB(TESTSTRING)) Debug.Print "reversed = " _ & StrReverse(TESTSTRING) Debug.Print "first position of letter A (case-sensitive) = " _ & InStr(1, TESTSTRING, "A", vbBinaryCompare) Debug.Print "first position of letter A (case-insensitive) = " _ & InStr(1, TESTSTRING, "A", vbTextCompare) Debug.Print "concatenated with & TESTSTRING & "123" End Sub