WeixiangYan/CodeTransOcean huggingface dataset:
Task: Strip a set of characters from a string


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

std::string stripchars(std::string str, const std::string &chars)
{
    str.erase(
        std::remove_if(str.begin(), str.end(), [&](char c){
            return chars.find(c) != std::string::npos;
        }),
        str.end()
    );
    return str;
}

int main()
{
    std::cout << stripchars("She was a soul stripper. She took my heart!", "aei") << '\n';
    return 0;
}










Ada: with Ada.Text_IO;

procedure Strip_Characters_From_String is

   function Strip(The_String: String; The_Characters: String)
                  return String is
      Keep:   array (Character) of Boolean := (others => True);
      Result: String(The_String'Range);
      Last:   Natural := Result'First-1;
   begin
      for I in The_Characters'Range loop
         Keep(The_Characters(I)) := False;
      end loop;
      for J in The_String'Range loop
         if Keep(The_String(J)) then
            Last := Last+1;
            Result(Last) := The_String(J);
         end if;
      end loop;
      return Result(Result'First .. Last);
   end Strip;

   S: String := "She was a soul stripper. She took my heart!";

begin 
   Ada.Text_IO.Put_Line(Strip(S, "aei"));
end Strip_Characters_From_String;
Task: Strip a set of characters from a string




Go: package main

import (
    "fmt"
    "strings"
)

func stripchars(str, chr string) string {
    return strings.Map(func(r rune) rune {
        if strings.IndexRune(chr, r) < 0 {
            return r
        }
        return -1
    }, str)
}

func main() {
    fmt.Println(stripchars("She was a soul stripper. She took my heart!",
        "aei"))
}








Ada: with Ada.Text_IO;

procedure Strip_Characters_From_String is

   function Strip(The_String: String; The_Characters: String)
                  return String is
      Keep:   array (Character) of Boolean := (others => True);
      Result: String(The_String'Range);
      Last:   Natural := Result'First-1;
   begin
      for I in The_Characters'Range loop
         Keep(The_Characters(I)) := False;
      end loop;
      for J in The_String'Range loop
         if Keep(The_String(J)) then
            Last := Last+1;
            Result(Last) := The_String(J);
         end if;
      end loop;
      return Result(Result'First .. Last);
   end Strip;

   S: String := "She was a soul stripper. She took my heart!";

begin 
   Ada.Text_IO.Put_Line(Strip(S, "aei"));
end Strip_Characters_From_String;
Task: Strip a set of characters from a string





Java: class StripChars {
    public static String stripChars(String inString, String toStrip) {
        return inString.replaceAll("[" + toStrip + "]", "");
    }

    public static void main(String[] args) {
        String sentence = "She was a soul stripper. She took my heart!";
        String chars = "aei";
        System.out.println("sentence: " + sentence);
        System.out.println("to strip: " + chars);
        System.out.println("stripped: " + stripChars(sentence, chars));
    }
}







Ada: with Ada.Text_IO;

procedure Strip_Characters_From_String is

   function Strip(The_String: String; The_Characters: String)
                  return String is
      Keep:   array (Character) of Boolean := (others => True);
      Result: String(The_String'Range);
      Last:   Natural := Result'First-1;
   begin
      for I in The_Characters'Range loop
         Keep(The_Characters(I)) := False;
      end loop;
      for J in The_String'Range loop
         if Keep(The_String(J)) then
            Last := Last+1;
            Result(Last) := The_String(J);
         end if;
      end loop;
      return Result(Result'First .. Last);
   end Strip;

   S: String := "She was a soul stripper. She took my heart!";

begin 
   Ada.Text_IO.Put_Line(Strip(S, "aei"));
end Strip_Characters_From_String;
Task: Strip a set of characters from a string







Python: >>> def stripchars(s, chars):
...     return s.translate(None, chars)
... 
>>> stripchars("She was a soul stripper. She took my heart!", "aei")
'Sh ws  soul strppr. Sh took my hrt!'





Ada: with Ada.Text_IO;

procedure Strip_Characters_From_String is

   function Strip(The_String: String; The_Characters: String)
                  return String is
      Keep:   array (Character) of Boolean := (others => True);
      Result: String(The_String'Range);
      Last:   Natural := Result'First-1;
   begin
      for I in The_Characters'Range loop
         Keep(The_Characters(I)) := False;
      end loop;
      for J in The_String'Range loop
         if Keep(The_String(J)) then
            Last := Last+1;
            Result(Last) := The_String(J);
         end if;
      end loop;
      return Result(Result'First .. Last);
   end Strip;

   S: String := "She was a soul stripper. She took my heart!";

begin 
   Ada.Text_IO.Put_Line(Strip(S, "aei"));
end Strip_Characters_From_String;
Task: Strip a set of characters from a string








VB: Function StripChars(stString As String, stStripChars As String, Optional bSpace As Boolean)
Dim i As Integer, stReplace As String
    If bSpace = True Then
        stReplace = " "
    Else
        stReplace = ""
    End If
    For i = 1 To Len(stStripChars)
        stString = Replace(stString, Mid(stStripChars, i, 1), stReplace)
    Next i
    StripChars = stString
End Function




Ada: with Ada.Text_IO;

procedure Strip_Characters_From_String is

   function Strip(The_String: String; The_Characters: String)
                  return String is
      Keep:   array (Character) of Boolean := (others => True);
      Result: String(The_String'Range);
      Last:   Natural := Result'First-1;
   begin
      for I in The_Characters'Range loop
         Keep(The_Characters(I)) := False;
      end loop;
      for J in The_String'Range loop
         if Keep(The_String(J)) then
            Last := Last+1;
            Result(Last) := The_String(J);
         end if;
      end loop;
      return Result(Result'First .. Last);
   end Strip;

   S: String := "She was a soul stripper. She took my heart!";

begin 
   Ada.Text_IO.Put_Line(Strip(S, "aei"));
end Strip_Characters_From_String;
Task: Strip a set of characters from a string

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

  
char *strip_chars(const char *string, const char *chars)
{
  char * newstr = malloc(strlen(string) + 1);
  int counter = 0;

  for ( ; *string; string++) {
    if (!strchr(chars, *string)) {
      newstr[ counter ] = *string;
      ++ counter;
    }
  }

  newstr[counter] = 0;
  return newstr;
}

int main(void)
{
  char *new = strip_chars("She was a soul stripper. She took my heart!", "aei");
  printf("%s\n", new);

  free(new);
  return 0;
}
Task: Strip a set of characters from a string



C#: using System;

public static string RemoveCharactersFromString(string testString, string removeChars)
{
    char[] charAry = removeChars.ToCharArray();
    string returnString = testString;
    foreach (char c in charAry)
    {
        while (returnString.IndexOf(c) > -1)
        {
            returnString = returnString.Remove(returnString.IndexOf(c), 1);
        }
    }
    return returnString;
}
Task: Strip a set of characters from a string


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

std::string stripchars(std::string str, const std::string &chars)
{
    str.erase(
        std::remove_if(str.begin(), str.end(), [&](char c){
            return chars.find(c) != std::string::npos;
        }),
        str.end()
    );
    return str;
}

int main()
{
    std::cout << stripchars("She was a soul stripper. She took my heart!", "aei") << '\n';
    return 0;
}
Task: Strip a set of characters from a string





Java: class StripChars {
    public static String stripChars(String inString, String toStrip) {
        return inString.replaceAll("[" + toStrip + "]", "");
    }

    public static void main(String[] args) {
        String sentence = "She was a soul stripper. She took my heart!";
        String chars = "aei";
        System.out.println("sentence: " + sentence);
        System.out.println("to strip: " + chars);
        System.out.println("stripped: " + stripChars(sentence, chars));
    }
}
Task: Strip a set of characters from a string







Python: >>> def stripchars(s, chars):
...     return s.translate(None, chars)
... 
>>> stripchars("She was a soul stripper. She took my heart!", "aei")
'Sh ws  soul strppr. Sh took my hrt!'
Task: Strip a set of characters from a string








VB: Function StripChars(stString As String, stStripChars As String, Optional bSpace As Boolean)
Dim i As Integer, stReplace As String
    If bSpace = True Then
        stReplace = " "
    Else
        stReplace = ""
    End If
    For i = 1 To Len(stStripChars)
        stString = Replace(stString, Mid(stStripChars, i, 1), stReplace)
    Next i
    StripChars = stString
End Function
Task: Strip a set of characters from a string




Go: package main

import (
    "fmt"
    "strings"
)

func stripchars(str, chr string) string {
    return strings.Map(func(r rune) rune {
        if strings.IndexRune(chr, r) < 0 {
            return r
        }
        return -1
    }, str)
}

func main() {
    fmt.Println(stripchars("She was a soul stripper. She took my heart!",
        "aei"))
}
Task: Strip a set of characters from a string



C#: using System;

public static string RemoveCharactersFromString(string testString, string removeChars)
{
    char[] charAry = removeChars.ToCharArray();
    string returnString = testString;
    foreach (char c in charAry)
    {
        while (returnString.IndexOf(c) > -1)
        {
            returnString = returnString.Remove(returnString.IndexOf(c), 1);
        }
    }
    return returnString;
}








Fortran: elemental subroutine strip(string,set)
  character(len=*), intent(inout) :: string
  character(len=*), intent(in)    :: set
  integer                         :: old, new, stride
  old = 1; new = 1
  do
    stride = scan( string( old : ), set )
    if ( stride > 0 ) then
      string( new : new+stride-2 ) = string( old : old+stride-2 )
      old = old+stride
      new = new+stride-1
    else
      string( new : ) = string( old : )
      return
    end if
  end do
end subroutine strip
Task: Strip a set of characters from a string


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

std::string stripchars(std::string str, const std::string &chars)
{
    str.erase(
        std::remove_if(str.begin(), str.end(), [&](char c){
            return chars.find(c) != std::string::npos;
        }),
        str.end()
    );
    return str;
}

int main()
{
    std::cout << stripchars("She was a soul stripper. She took my heart!", "aei") << '\n';
    return 0;
}









Fortran: elemental subroutine strip(string,set)
  character(len=*), intent(inout) :: string
  character(len=*), intent(in)    :: set
  integer                         :: old, new, stride
  old = 1; new = 1
  do
    stride = scan( string( old : ), set )
    if ( stride > 0 ) then
      string( new : new+stride-2 ) = string( old : old+stride-2 )
      old = old+stride
      new = new+stride-1
    else
      string( new : ) = string( old : )
      return
    end if
  end do
end subroutine strip
Task: Strip a set of characters from a string

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

  
char *strip_chars(const char *string, const char *chars)
{
  char * newstr = malloc(strlen(string) + 1);
  int counter = 0;

  for ( ; *string; string++) {
    if (!strchr(chars, *string)) {
      newstr[ counter ] = *string;
      ++ counter;
    }
  }

  newstr[counter] = 0;
  return newstr;
}

int main(void)
{
  char *new = strip_chars("She was a soul stripper. She took my heart!", "aei");
  printf("%s\n", new);

  free(new);
  return 0;
}










Fortran: elemental subroutine strip(string,set)
  character(len=*), intent(inout) :: string
  character(len=*), intent(in)    :: set
  integer                         :: old, new, stride
  old = 1; new = 1
  do
    stride = scan( string( old : ), set )
    if ( stride > 0 ) then
      string( new : new+stride-2 ) = string( old : old+stride-2 )
      old = old+stride
      new = new+stride-1
    else
      string( new : ) = string( old : )
      return
    end if
  end do
end subroutine strip
Task: Strip a set of characters from a string





Java: class StripChars {
    public static String stripChars(String inString, String toStrip) {
        return inString.replaceAll("[" + toStrip + "]", "");
    }

    public static void main(String[] args) {
        String sentence = "She was a soul stripper. She took my heart!";
        String chars = "aei";
        System.out.println("sentence: " + sentence);
        System.out.println("to strip: " + chars);
        System.out.println("stripped: " + stripChars(sentence, chars));
    }
}






Fortran: elemental subroutine strip(string,set)
  character(len=*), intent(inout) :: string
  character(len=*), intent(in)    :: set
  integer                         :: old, new, stride
  old = 1; new = 1
  do
    stride = scan( string( old : ), set )
    if ( stride > 0 ) then
      string( new : new+stride-2 ) = string( old : old+stride-2 )
      old = old+stride
      new = new+stride-1
    else
      string( new : ) = string( old : )
      return
    end if
  end do
end subroutine strip
Task: Strip a set of characters from a string







Python: >>> def stripchars(s, chars):
...     return s.translate(None, chars)
... 
>>> stripchars("She was a soul stripper. She took my heart!", "aei")
'Sh ws  soul strppr. Sh took my hrt!'




Fortran: elemental subroutine strip(string,set)
  character(len=*), intent(inout) :: string
  character(len=*), intent(in)    :: set
  integer                         :: old, new, stride
  old = 1; new = 1
  do
    stride = scan( string( old : ), set )
    if ( stride > 0 ) then
      string( new : new+stride-2 ) = string( old : old+stride-2 )
      old = old+stride
      new = new+stride-1
    else
      string( new : ) = string( old : )
      return
    end if
  end do
end subroutine strip
Task: Strip a set of characters from a string








VB: Function StripChars(stString As String, stStripChars As String, Optional bSpace As Boolean)
Dim i As Integer, stReplace As String
    If bSpace = True Then
        stReplace = " "
    Else
        stReplace = ""
    End If
    For i = 1 To Len(stStripChars)
        stString = Replace(stString, Mid(stStripChars, i, 1), stReplace)
    Next i
    StripChars = stString
End Function



Fortran: elemental subroutine strip(string,set)
  character(len=*), intent(inout) :: string
  character(len=*), intent(in)    :: set
  integer                         :: old, new, stride
  old = 1; new = 1
  do
    stride = scan( string( old : ), set )
    if ( stride > 0 ) then
      string( new : new+stride-2 ) = string( old : old+stride-2 )
      old = old+stride
      new = new+stride-1
    else
      string( new : ) = string( old : )
      return
    end if
  end do
end subroutine strip
Task: Strip a set of characters from a string






PHP: <?php
function stripchars($s, $chars) {
    return str_replace(str_split($chars), "", $s);
}

echo stripchars("She was a soul stripper. She took my heart!", "aei"), "\n";
?>





Fortran: elemental subroutine strip(string,set)
  character(len=*), intent(inout) :: string
  character(len=*), intent(in)    :: set
  integer                         :: old, new, stride
  old = 1; new = 1
  do
    stride = scan( string( old : ), set )
    if ( stride > 0 ) then
      string( new : new+stride-2 ) = string( old : old+stride-2 )
      old = old+stride
      new = new+stride-1
    else
      string( new : ) = string( old : )
      return
    end if
  end do
end subroutine strip
Task: Strip a set of characters from a string

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

  
char *strip_chars(const char *string, const char *chars)
{
  char * newstr = malloc(strlen(string) + 1);
  int counter = 0;

  for ( ; *string; string++) {
    if (!strchr(chars, *string)) {
      newstr[ counter ] = *string;
      ++ counter;
    }
  }

  newstr[counter] = 0;
  return newstr;
}

int main(void)
{
  char *new = strip_chars("She was a soul stripper. She took my heart!", "aei");
  printf("%s\n", new);

  free(new);
  return 0;
}









COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. Strip-Chars.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  Str-Size  CONSTANT 128.

       LOCAL-STORAGE SECTION.
       01  I       PIC 999.
       01  Str-Pos PIC 999.

       01  Offset  PIC 999.
       01  New-Pos PIC 999.

       01  Str-End PIC 999.

       LINKAGE SECTION.
       01  Str     PIC X(Str-Size).
       01  Chars-To-Replace PIC X(256).

       PROCEDURE DIVISION USING Str BY VALUE Chars-To-Replace.
       Main.
           PERFORM VARYING I FROM 1 BY 1
                   UNTIL Chars-To-Replace (I:1) = X"00"

               MOVE ZERO TO Offset

*              
*              
               PERFORM VARYING Str-Pos FROM 1 BY 1
                       UNTIL Str-Size < Str-Pos
                   IF Str (Str-Pos:1) = Chars-To-Replace (I:1)
                       ADD 1 TO Offset
                   ELSE IF Offset NOT = ZERO
                       COMPUTE New-Pos = Str-Pos - Offset
                       MOVE Str (Str-Pos:1) TO Str (New-Pos:1)
                   END-IF
               END-PERFORM
               
*              
*              
               COMPUTE Str-End = Str-Size - Offset
               MOVE SPACES TO Str (Str-End:Offset)
           END-PERFORM

           GOBACK
           .
Task: Strip a set of characters from a string



C#: using System;

public static string RemoveCharactersFromString(string testString, string removeChars)
{
    char[] charAry = removeChars.ToCharArray();
    string returnString = testString;
    foreach (char c in charAry)
    {
        while (returnString.IndexOf(c) > -1)
        {
            returnString = returnString.Remove(returnString.IndexOf(c), 1);
        }
    }
    return returnString;
}







COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. Strip-Chars.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  Str-Size  CONSTANT 128.

       LOCAL-STORAGE SECTION.
       01  I       PIC 999.
       01  Str-Pos PIC 999.

       01  Offset  PIC 999.
       01  New-Pos PIC 999.

       01  Str-End PIC 999.

       LINKAGE SECTION.
       01  Str     PIC X(Str-Size).
       01  Chars-To-Replace PIC X(256).

       PROCEDURE DIVISION USING Str BY VALUE Chars-To-Replace.
       Main.
           PERFORM VARYING I FROM 1 BY 1
                   UNTIL Chars-To-Replace (I:1) = X"00"

               MOVE ZERO TO Offset

*              
*              
               PERFORM VARYING Str-Pos FROM 1 BY 1
                       UNTIL Str-Size < Str-Pos
                   IF Str (Str-Pos:1) = Chars-To-Replace (I:1)
                       ADD 1 TO Offset
                   ELSE IF Offset NOT = ZERO
                       COMPUTE New-Pos = Str-Pos - Offset
                       MOVE Str (Str-Pos:1) TO Str (New-Pos:1)
                   END-IF
               END-PERFORM
               
*              
*              
               COMPUTE Str-End = Str-Size - Offset
               MOVE SPACES TO Str (Str-End:Offset)
           END-PERFORM

           GOBACK
           .
Task: Strip a set of characters from a string


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

std::string stripchars(std::string str, const std::string &chars)
{
    str.erase(
        std::remove_if(str.begin(), str.end(), [&](char c){
            return chars.find(c) != std::string::npos;
        }),
        str.end()
    );
    return str;
}

int main()
{
    std::cout << stripchars("She was a soul stripper. She took my heart!", "aei") << '\n';
    return 0;
}








COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. Strip-Chars.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  Str-Size  CONSTANT 128.

       LOCAL-STORAGE SECTION.
       01  I       PIC 999.
       01  Str-Pos PIC 999.

       01  Offset  PIC 999.
       01  New-Pos PIC 999.

       01  Str-End PIC 999.

       LINKAGE SECTION.
       01  Str     PIC X(Str-Size).
       01  Chars-To-Replace PIC X(256).

       PROCEDURE DIVISION USING Str BY VALUE Chars-To-Replace.
       Main.
           PERFORM VARYING I FROM 1 BY 1
                   UNTIL Chars-To-Replace (I:1) = X"00"

               MOVE ZERO TO Offset

*              
*              
               PERFORM VARYING Str-Pos FROM 1 BY 1
                       UNTIL Str-Size < Str-Pos
                   IF Str (Str-Pos:1) = Chars-To-Replace (I:1)
                       ADD 1 TO Offset
                   ELSE IF Offset NOT = ZERO
                       COMPUTE New-Pos = Str-Pos - Offset
                       MOVE Str (Str-Pos:1) TO Str (New-Pos:1)
                   END-IF
               END-PERFORM
               
*              
*              
               COMPUTE Str-End = Str-Size - Offset
               MOVE SPACES TO Str (Str-End:Offset)
           END-PERFORM

           GOBACK
           .
Task: Strip a set of characters from a string





Java: class StripChars {
    public static String stripChars(String inString, String toStrip) {
        return inString.replaceAll("[" + toStrip + "]", "");
    }

    public static void main(String[] args) {
        String sentence = "She was a soul stripper. She took my heart!";
        String chars = "aei";
        System.out.println("sentence: " + sentence);
        System.out.println("to strip: " + chars);
        System.out.println("stripped: " + stripChars(sentence, chars));
    }
}





COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. Strip-Chars.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  Str-Size  CONSTANT 128.

       LOCAL-STORAGE SECTION.
       01  I       PIC 999.
       01  Str-Pos PIC 999.

       01  Offset  PIC 999.
       01  New-Pos PIC 999.

       01  Str-End PIC 999.

       LINKAGE SECTION.
       01  Str     PIC X(Str-Size).
       01  Chars-To-Replace PIC X(256).

       PROCEDURE DIVISION USING Str BY VALUE Chars-To-Replace.
       Main.
           PERFORM VARYING I FROM 1 BY 1
                   UNTIL Chars-To-Replace (I:1) = X"00"

               MOVE ZERO TO Offset

*              
*              
               PERFORM VARYING Str-Pos FROM 1 BY 1
                       UNTIL Str-Size < Str-Pos
                   IF Str (Str-Pos:1) = Chars-To-Replace (I:1)
                       ADD 1 TO Offset
                   ELSE IF Offset NOT = ZERO
                       COMPUTE New-Pos = Str-Pos - Offset
                       MOVE Str (Str-Pos:1) TO Str (New-Pos:1)
                   END-IF
               END-PERFORM
               
*              
*              
               COMPUTE Str-End = Str-Size - Offset
               MOVE SPACES TO Str (Str-End:Offset)
           END-PERFORM

           GOBACK
           .