WeixiangYan/CodeTransOcean huggingface dataset:
Task: Environment variables





Java: System.getenv("HOME") 
System.getenv()       







Ada: with Ada.Environment_Variables; use Ada.Environment_Variables;
with Ada.Text_Io; use Ada.Text_Io;

procedure Print_Path is
begin
   Put_Line("Path : " & Value("PATH"));
end Print_Path;
Task: Environment variables







Python: import os
os.environ['HOME']





Ada: with Ada.Environment_Variables; use Ada.Environment_Variables;
with Ada.Text_Io; use Ada.Text_Io;

procedure Print_Path is
begin
   Put_Line("Path : " & Value("PATH"));
end Print_Path;
Task: Environment variables








VB: Debug.Print Environ$("PATH")




Ada: with Ada.Environment_Variables; use Ada.Environment_Variables;
with Ada.Text_Io; use Ada.Text_Io;

procedure Print_Path is
begin
   Put_Line("Path : " & Value("PATH"));
end Print_Path;
Task: Environment variables

C: #include <stdlib.h>
#include <stdio.h>
 
int main() {
  puts(getenv("HOME"));
  puts(getenv("PATH"));
  puts(getenv("USER"));
  return 0;
}
Task: Environment variables



C#: using System;

namespace RosettaCode {
    class Program {
        static void Main() {
            string temp = Environment.GetEnvironmentVariable("TEMP");
            Console.WriteLine("TEMP is " + temp);
        }
    }
}
Task: Environment variables


C++: #include <cstdlib>
#include <cstdio>

int main()
{
   puts(getenv("HOME"));
   return 0;
}
Task: Environment variables





Java: System.getenv("HOME") 
System.getenv()
Task: Environment variables




Go: package main

import (
    "fmt"
    "os"
)

func main() {
    fmt.Println(os.Getenv("SHELL"))
}
Task: Environment variables







Python: import os
os.environ['HOME']
Task: Environment variables








VB: Debug.Print Environ$("PATH")
Task: Environment variables



C#: using System;

namespace RosettaCode {
    class Program {
        static void Main() {
            string temp = Environment.GetEnvironmentVariable("TEMP");
            Console.WriteLine("TEMP is " + temp);
        }
    }
}








Fortran: program show_home
implicit none
character(len=32) :: home_val  
integer           :: home_len  
integer           :: stat      
                               
                               
                               
call get_environment_variable('HOME', home_val, home_len, stat)
if (stat == 0) then
    write(*,'(a)') 'HOME = '//trim(home_val)
else
    write(*,'(a)') 'No HOME to go to
end if
end program show_home
Task: Environment variables


C++: #include <cstdlib>
#include <cstdio>

int main()
{
   puts(getenv("HOME"));
   return 0;
}









Fortran: program show_home
implicit none
character(len=32) :: home_val  
integer           :: home_len  
integer           :: stat      
                               
                               
                               
call get_environment_variable('HOME', home_val, home_len, stat)
if (stat == 0) then
    write(*,'(a)') 'HOME = '//trim(home_val)
else
    write(*,'(a)') 'No HOME to go to
end if
end program show_home
Task: Environment variables

C: #include <stdlib.h>
#include <stdio.h>
 
int main() {
  puts(getenv("HOME"));
  puts(getenv("PATH"));
  puts(getenv("USER"));
  return 0;
}










Fortran: program show_home
implicit none
character(len=32) :: home_val  
integer           :: home_len  
integer           :: stat      
                               
                               
                               
call get_environment_variable('HOME', home_val, home_len, stat)
if (stat == 0) then
    write(*,'(a)') 'HOME = '//trim(home_val)
else
    write(*,'(a)') 'No HOME to go to
end if
end program show_home
Task: Environment variables




Go: package main

import (
    "fmt"
    "os"
)

func main() {
    fmt.Println(os.Getenv("SHELL"))
}







Fortran: program show_home
implicit none
character(len=32) :: home_val  
integer           :: home_len  
integer           :: stat      
                               
                               
                               
call get_environment_variable('HOME', home_val, home_len, stat)
if (stat == 0) then
    write(*,'(a)') 'HOME = '//trim(home_val)
else
    write(*,'(a)') 'No HOME to go to
end if
end program show_home
Task: Environment variables





Java: System.getenv("HOME") 
System.getenv()       






Fortran: program show_home
implicit none
character(len=32) :: home_val  
integer           :: home_len  
integer           :: stat      
                               
                               
                               
call get_environment_variable('HOME', home_val, home_len, stat)
if (stat == 0) then
    write(*,'(a)') 'HOME = '//trim(home_val)
else
    write(*,'(a)') 'No HOME to go to
end if
end program show_home
Task: Environment variables







Python: import os
os.environ['HOME']




Fortran: program show_home
implicit none
character(len=32) :: home_val  
integer           :: home_len  
integer           :: stat      
                               
                               
                               
call get_environment_variable('HOME', home_val, home_len, stat)
if (stat == 0) then
    write(*,'(a)') 'HOME = '//trim(home_val)
else
    write(*,'(a)') 'No HOME to go to
end if
end program show_home
Task: Environment variables






PHP: $_ENV['HOME']





Fortran: program show_home
implicit none
character(len=32) :: home_val  
integer           :: home_len  
integer           :: stat      
                               
                               
                               
call get_environment_variable('HOME', home_val, home_len, stat)
if (stat == 0) then
    write(*,'(a)') 'HOME = '//trim(home_val)
else
    write(*,'(a)') 'No HOME to go to
end if
end program show_home
Task: Environment variables

C: #include <stdlib.h>
#include <stdio.h>
 
int main() {
  puts(getenv("HOME"));
  puts(getenv("PATH"));
  puts(getenv("USER"));
  return 0;
}









COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. Environment-Vars.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  home PIC X(75).

       PROCEDURE DIVISION.
*          
           ACCEPT home FROM ENVIRONMENT "HOME"
           DISPLAY home

*          
           DISPLAY "HOME" UPON ENVIRONMENT-NAME
           ACCEPT home FROM ENVIRONMENT-VALUE

           GOBACK
           .
Task: Environment variables



C#: using System;

namespace RosettaCode {
    class Program {
        static void Main() {
            string temp = Environment.GetEnvironmentVariable("TEMP");
            Console.WriteLine("TEMP is " + temp);
        }
    }
}







COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. Environment-Vars.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  home PIC X(75).

       PROCEDURE DIVISION.
*          
           ACCEPT home FROM ENVIRONMENT "HOME"
           DISPLAY home

*          
           DISPLAY "HOME" UPON ENVIRONMENT-NAME
           ACCEPT home FROM ENVIRONMENT-VALUE

           GOBACK
           .
Task: Environment variables


C++: #include <cstdlib>
#include <cstdio>

int main()
{
   puts(getenv("HOME"));
   return 0;
}








COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. Environment-Vars.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  home PIC X(75).

       PROCEDURE DIVISION.
*          
           ACCEPT home FROM ENVIRONMENT "HOME"
           DISPLAY home

*          
           DISPLAY "HOME" UPON ENVIRONMENT-NAME
           ACCEPT home FROM ENVIRONMENT-VALUE

           GOBACK
           .
Task: Environment variables





Java: System.getenv("HOME") 
System.getenv()       





COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. Environment-Vars.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  home PIC X(75).

       PROCEDURE DIVISION.
*          
           ACCEPT home FROM ENVIRONMENT "HOME"
           DISPLAY home

*          
           DISPLAY "HOME" UPON ENVIRONMENT-NAME
           ACCEPT home FROM ENVIRONMENT-VALUE

           GOBACK
           .
Task: Environment variables







Python: import os
os.environ['HOME']



COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. Environment-Vars.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  home PIC X(75).

       PROCEDURE DIVISION.
*          
           ACCEPT home FROM ENVIRONMENT "HOME"
           DISPLAY home

*          
           DISPLAY "HOME" UPON ENVIRONMENT-NAME
           ACCEPT home FROM ENVIRONMENT-VALUE

           GOBACK
           .
Task: Environment variables








VB: Debug.Print Environ$("PATH")


COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. Environment-Vars.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  home PIC X(75).

       PROCEDURE DIVISION.
*          
           ACCEPT home FROM ENVIRONMENT "HOME"
           DISPLAY home

*          
           DISPLAY "HOME" UPON ENVIRONMENT-NAME
           ACCEPT home FROM ENVIRONMENT-VALUE

           GOBACK
           .
Task: Environment variables




Go: package main

import (
    "fmt"
    "os"
)

func main() {
    fmt.Println(os.Getenv("SHELL"))
}






COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. Environment-Vars.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  home PIC X(75).

       PROCEDURE DIVISION.
*          
           ACCEPT home FROM ENVIRONMENT "HOME"
           DISPLAY home

*          
           DISPLAY "HOME" UPON ENVIRONMENT-NAME
           ACCEPT home FROM ENVIRONMENT-VALUE

           GOBACK
           .
Task: Environment variables






PHP: $_ENV['HOME']
Task: Environment variables






PHP: $_ENV['HOME']






Ada: with Ada.Environment_Variables; use Ada.Environment_Variables;
with Ada.Text_Io; use Ada.Text_Io;

procedure Print_Path is
begin
   Put_Line("Path : " & Value("PATH"));
end Print_Path;
Task: Environment variables






PHP: $_ENV['HOME']




COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. Environment-Vars.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  home PIC X(75).

       PROCEDURE DIVISION.
*          
           ACCEPT home FROM ENVIRONMENT "HOME"
           DISPLAY home

*          
           DISPLAY "HOME" UPON ENVIRONMENT-NAME
           ACCEPT home FROM ENVIRONMENT-VALUE

           GOBACK
           .
Task: Substring



C#: using System;
namespace SubString
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = "0123456789";
            const int n = 3;
            const int m = 2;
            const char c = '3';
            const string z = "345";

            
            Console.WriteLine(s.Substring(n, m));
            
            Console.WriteLine(s.Substring(n, s.Length - n));
            
            Console.WriteLine(s.Substring(0, s.Length - 1));
            
            Console.WriteLine(s.Substring(s.IndexOf(c), m));
            
            Console.WriteLine(s.Substring(s.IndexOf(z), m));
        }
    }
}









Ada: type String is array (Positive range <>) of Character;
Task: Substring

C: 
#define _CRT_SECURE_NO_WARNINGS 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


void putm(char* string, size_t m)
{
    while(*string && m--)
        putchar(*string++);
}

int main(void)
{

    char string[] = 
        "Programs for other encodings (such as 8-bit ASCII, or EUC-JP)."

    int n = 3;
    int m = 4;
    char knownCharacter = '(';
    char knownSubstring[] = "encodings";

    putm(string+n-1, m );                       putchar('\n');
    puts(string+n+1);                           putchar('\n');
    putm(string, strlen(string)-1);             putchar('\n');
    putm(strchr(string, knownCharacter), m );   putchar('\n');
    putm(strstr(string, knownSubstring), m );   putchar('\n');

    return EXIT_SUCCESS;
}











Ada: type String is array (Positive range <>) of Character;
Task: Substring


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

int main()
{
  std::string s = "0123456789";

  int const n = 3;
  int const m = 4;
  char const c = '2';
  std::string const sub = "456";

  std::cout << s.substr(n, m)<< "\n";
  std::cout << s.substr(n) << "\n";
  std::cout << s.substr(0, s.size()-1) << "\n";
  std::cout << s.substr(s.find(c), m) << "\n";
  std::cout << s.substr(s.find(sub), m) << "\n";
}










Ada: type String is array (Positive range <>) of Character;
Task: Substring




Go: package main

import (
    "fmt"
    "strings"
)

func main() {
    s := "ABCDEFGH"
    n, m := 2, 3
    
    fmt.Println("Index: ", "01234567")
    fmt.Println("String:", s)
    
    fmt.Printf("Start %d, length %d:    %s\n", n, m, s[n : n+m])
    
    fmt.Printf("Start %d, to end:      %s\n", n, s[n:])
    
    fmt.Printf("All but last:         %s\n", s[:len(s)-1])
    
    dx := strings.IndexByte(s, 'D')
    fmt.Printf("Start 'D', length %d:  %s\n", m, s[dx : dx+m])
    
    sx := strings.Index(s, "DE")
    fmt.Printf(`Start "DE", length %d: %s`+"\n", m, s[sx : sx+m])
}








Ada: type String is array (Positive range <>) of Character;
Task: Substring





Java: public static String Substring(String str, int n, int m){
    return str.substring(n, n+m);
}
public static String Substring(String str, int n){
    return str.substring(n);
}
public static String Substring(String str){
    return str.substring(0, str.length()-1);
}
public static String Substring(String str, char c, int m){
    return str.substring(str.indexOf(c), str.indexOf(c)+m+1);
}
public static String Substring(String str, String sub, int m){
    return str.substring(str.indexOf(sub), str.indexOf(sub)+m+1);
}







Ada: type String is array (Positive range <>) of Character;
Task: Substring







Python: >>> s = 'abcdefgh'
>>> n, m, char, chars = 2, 3, 'd', 'cd'
>>> 
>>> s[n-1:n+m-1]
'bcd'
>>> 
>>> s[n-1:]
'bcdefgh'
>>> 
>>> s[:-1]
'abcdefg'
>>> 
>>> indx = s.index(char)
>>> s[indx:indx+m]
'def'
>>> 
>>> indx = s.index(chars)
>>> s[indx:indx+m]
'cde'
>>>





Ada: type String is array (Positive range <>) of Character;
Task: Substring








VB: Public Sub substring()





 
    sentence = "the last thing the man said was the"
    n = 10: m = 5
       
    
    Debug.Print Mid(sentence, n, 5)
    
    Debug.Print Right(sentence, Len(sentence) - n + 1)
    
    Debug.Print Left(sentence, Len(sentence) - 1)
    
    k = InStr(1, sentence, "m")
    Debug.Print Mid(sentence, k, 5)
    
    k = InStr(1, sentence, "aid")
    Debug.Print Mid(sentence, k, 5)
End Sub




Ada: type String is array (Positive range <>) of Character;
Task: Substring

C: 
#define _CRT_SECURE_NO_WARNINGS 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


void putm(char* string, size_t m)
{
    while(*string && m--)
        putchar(*string++);
}

int main(void)
{

    char string[] = 
        "Programs for other encodings (such as 8-bit ASCII, or EUC-JP)."

    int n = 3;
    int m = 4;
    char knownCharacter = '(';
    char knownSubstring[] = "encodings";

    putm(string+n-1, m );                       putchar('\n');
    puts(string+n+1);                           putchar('\n');
    putm(string, strlen(string)-1);             putchar('\n');
    putm(strchr(string, knownCharacter), m );   putchar('\n');
    putm(strstr(string, knownSubstring), m );   putchar('\n');

    return EXIT_SUCCESS;
}
Task: Substring



C#: using System;
namespace SubString
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = "0123456789";
            const int n = 3;
            const int m = 2;
            const char c = '3';
            const string z = "345";

            
            Console.WriteLine(s.Substring(n, m));
            
            Console.WriteLine(s.Substring(n, s.Length - n));
            
            Console.WriteLine(s.Substring(0, s.Length - 1));
            
            Console.WriteLine(s.Substring(s.IndexOf(c), m));
            
            Console.WriteLine(s.Substring(s.IndexOf(z), m));
        }
    }
}
Task: Substring


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

int main()
{
  std::string s = "0123456789";

  int const n = 3;
  int const m = 4;
  char const c = '2';
  std::string const sub = "456";

  std::cout << s.substr(n, m)<< "\n";
  std::cout << s.substr(n) << "\n";
  std::cout << s.substr(0, s.size()-1) << "\n";
  std::cout << s.substr(s.find(c), m) << "\n";
  std::cout << s.substr(s.find(sub), m) << "\n";
}
Task: Substring





Java: public static String Substring(String str, int n, int m){
    return str.substring(n, n+m);
}
public static String Substring(String str, int n){
    return str.substring(n);
}
public static String Substring(String str){
    return str.substring(0, str.length()-1);
}
public static String Substring(String str, char c, int m){
    return str.substring(str.indexOf(c), str.indexOf(c)+m+1);
}
public static String Substring(String str, String sub, int m){
    return str.substring(str.indexOf(sub), str.indexOf(sub)+m+1);
}
Task: Substring







Python: >>> s = 'abcdefgh'
>>> n, m, char, chars = 2, 3, 'd', 'cd'
>>> 
>>> s[n-1:n+m-1]
'bcd'
>>> 
>>> s[n-1:]
'bcdefgh'
>>> 
>>> s[:-1]
'abcdefg'
>>> 
>>> indx = s.index(char)
>>> s[indx:indx+m]
'def'
>>> 
>>> indx = s.index(chars)
>>> s[indx:indx+m]
'cde'
>>>
Task: Substring








VB: Public Sub substring()





 
    sentence = "the last thing the man said was the"
    n = 10: m = 5
       
    
    Debug.Print Mid(sentence, n, 5)
    
    Debug.Print Right(sentence, Len(sentence) - n + 1)
    
    Debug.Print Left(sentence, Len(sentence) - 1)
    
    k = InStr(1, sentence, "m")
    Debug.Print Mid(sentence, k, 5)
    
    k = InStr(1, sentence, "aid")
    Debug.Print Mid(sentence, k, 5)
End Sub
Task: Substring




Go: package main

import (
    "fmt"
    "strings"
)

func main() {
    s := "ABCDEFGH"
    n, m := 2, 3
    
    fmt.Println("Index: ", "01234567")
    fmt.Println("String:", s)
    
    fmt.Printf("Start %d, length %d:    %s\n", n, m, s[n : n+m])
    
    fmt.Printf("Start %d, to end:      %s\n", n, s[n:])
    
    fmt.Printf("All but last:         %s\n", s[:len(s)-1])
    
    dx := strings.IndexByte(s, 'D')
    fmt.Printf("Start 'D', length %d:  %s\n", m, s[dx : dx+m])
    
    sx := strings.Index(s, "DE")
    fmt.Printf(`Start "DE", length %d: %s`+"\n", m, s[sx : sx+m])
}
Task: Substring



C#: using System;
namespace SubString
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = "0123456789";
            const int n = 3;
            const int m = 2;
            const char c = '3';
            const string z = "345";

            
            Console.WriteLine(s.Substring(n, m));
            
            Console.WriteLine(s.Substring(n, s.Length - n));
            
            Console.WriteLine(s.Substring(0, s.Length - 1));
            
            Console.WriteLine(s.Substring(s.IndexOf(c), m));
            
            Console.WriteLine(s.Substring(s.IndexOf(z), m));
        }
    }
}








Fortran: program test_substring

  character (*), parameter :: string = 'The quick brown fox jumps over the lazy dog.'
  character (*), parameter :: substring = 'brown'
  character    , parameter :: c = 'q'
  integer      , parameter :: n = 5
  integer      , parameter :: m = 15
  integer                  :: i


  write (*, '(a)') string (n : n + m - 1)

  write (*, '(a)') string (n :)

  i = len (string) - 1
  write (*, '(a)') string (: i)

  i = index (string, c)
  write (*, '(a)') string (i : i + m - 1)

  i = index (string, substring)
  write (*, '(a)') string (i : i + m - 1)

end program test_substring
Task: Substring


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

int main()
{
  std::string s = "0123456789";

  int const n = 3;
  int const m = 4;
  char const c = '2';
  std::string const sub = "456";

  std::cout << s.substr(n, m)<< "\n";
  std::cout << s.substr(n) << "\n";
  std::cout << s.substr(0, s.size()-1) << "\n";
  std::cout << s.substr(s.find(c), m) << "\n";
  std::cout << s.substr(s.find(sub), m) << "\n";
}









Fortran: program test_substring

  character (*), parameter :: string = 'The quick brown fox jumps over the lazy dog.'
  character (*), parameter :: substring = 'brown'
  character    , parameter :: c = 'q'
  integer      , parameter :: n = 5
  integer      , parameter :: m = 15
  integer                  :: i


  write (*, '(a)') string (n : n + m - 1)

  write (*, '(a)') string (n :)

  i = len (string) - 1
  write (*, '(a)') string (: i)

  i = index (string, c)
  write (*, '(a)') string (i : i + m - 1)

  i = index (string, substring)
  write (*, '(a)') string (i : i + m - 1)

end program test_substring
Task: Substring

C: 
#define _CRT_SECURE_NO_WARNINGS 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


void putm(char* string, size_t m)
{
    while(*string && m--)
        putchar(*string++);
}

int main(void)
{

    char string[] = 
        "Programs for other encodings (such as 8-bit ASCII, or EUC-JP)."

    int n = 3;
    int m = 4;
    char knownCharacter = '(';
    char knownSubstring[] = "encodings";

    putm(string+n-1, m );                       putchar('\n');
    puts(string+n+1);                           putchar('\n');
    putm(string, strlen(string)-1);             putchar('\n');
    putm(strchr(string, knownCharacter), m );   putchar('\n');
    putm(strstr(string, knownSubstring), m );   putchar('\n');

    return EXIT_SUCCESS;
}










Fortran: program test_substring

  character (*), parameter :: string = 'The quick brown fox jumps over the lazy dog.'
  character (*), parameter :: substring = 'brown'
  character    , parameter :: c = 'q'
  integer      , parameter :: n = 5
  integer      , parameter :: m = 15
  integer                  :: i


  write (*, '(a)') string (n : n + m - 1)

  write (*, '(a)') string (n :)

  i = len (string) - 1
  write (*, '(a)') string (: i)

  i = index (string, c)
  write (*, '(a)') string (i : i + m - 1)

  i = index (string, substring)
  write (*, '(a)') string (i : i + m - 1)

end program test_substring
Task: Substring




Go: package main

import (
    "fmt"
    "strings"
)

func main() {
    s := "ABCDEFGH"
    n, m := 2, 3
    
    fmt.Println("Index: ", "01234567")
    fmt.Println("String:", s)
    
    fmt.Printf("Start %d, length %d:    %s\n", n, m, s[n : n+m])
    
    fmt.Printf("Start %d, to end:      %s\n", n, s[n:])
    
    fmt.Printf("All but last:         %s\n", s[:len(s)-1])
    
    dx := strings.IndexByte(s, 'D')
    fmt.Printf("Start 'D', length %d:  %s\n", m, s[dx : dx+m])
    
    sx := strings.Index(s, "DE")
    fmt.Printf(`Start "DE", length %d: %s`+"\n", m, s[sx : sx+m])
}







Fortran: program test_substring

  character (*), parameter :: string = 'The quick brown fox jumps over the lazy dog.'
  character (*), parameter :: substring = 'brown'
  character    , parameter :: c = 'q'
  integer      , parameter :: n = 5
  integer      , parameter :: m = 15
  integer                  :: i


  write (*, '(a)') string (n : n + m - 1)

  write (*, '(a)') string (n :)

  i = len (string) - 1
  write (*, '(a)') string (: i)

  i = index (string, c)
  write (*, '(a)') string (i : i + m - 1)

  i = index (string, substring)
  write (*, '(a)') string (i : i + m - 1)

end program test_substring
Task: Substring





Java: public static String Substring(String str, int n, int m){
    return str.substring(n, n+m);
}
public static String Substring(String str, int n){
    return str.substring(n);
}
public static String Substring(String str){
    return str.substring(0, str.length()-1);
}
public static String Substring(String str, char c, int m){
    return str.substring(str.indexOf(c), str.indexOf(c)+m+1);
}
public static String Substring(String str, String sub, int m){
    return str.substring(str.indexOf(sub), str.indexOf(sub)+m+1);
}






Fortran: program test_substring

  character (*), parameter :: string = 'The quick brown fox jumps over the lazy dog.'
  character (*), parameter :: substring = 'brown'
  character    , parameter :: c = 'q'
  integer      , parameter :: n = 5
  integer      , parameter :: m = 15
  integer                  :: i


  write (*, '(a)') string (n : n + m - 1)

  write (*, '(a)') string (n :)

  i = len (string) - 1
  write (*, '(a)') string (: i)

  i = index (string, c)
  write (*, '(a)') string (i : i + m - 1)

  i = index (string, substring)
  write (*, '(a)') string (i : i + m - 1)

end program test_substring