WeixiangYan/CodeTransOcean huggingface dataset:
Task: Euler's sum of powers conjecture








VB: Public Declare Function GetTickCount Lib "kernel32.dll" () As Long
Public Sub begin()
    start_int = GetTickCount()
    main
    Debug.Print (GetTickCount() - start_int) / 1000 & " seconds"
End Sub
Private Function pow(x, y) As Variant
    pow = CDec(Application.WorksheetFunction.Power(x, y))
End Function
Private Sub main()
    For x0 = 1 To 250
        For x1 = 1 To x0
            For x2 = 1 To x1
                For x3 = 1 To x2
                    sum = CDec(pow(x0, 5) + pow(x1, 5) + pow(x2, 5) + pow(x3, 5))
                    s1 = Int(pow(sum, 0.2))
                    If sum = pow(s1, 5) Then
                        Debug.Print x0 & "^5 + " & x1 & "^5 + " & x2 & "^5 + " & x3 & "^5 = " & s1
                        Exit Sub
                    End If
                Next x3
            Next x2
        Next x1
    Next x0
End Sub



Fortran: C EULER SUM OF POWERS CONJECTURE - FORTRAN IV
C FIND I1,I2,I3,I4,I5 : I1**5+I2**5+I3**5+I4**5=I5**5
      INTEGER I,P5(250),SUMX
      MAXN=250
      DO 1 I=1,MAXN
   1  P5(I)=I**5
      DO 6 I1=1,MAXN
      DO 6 I2=1,MAXN
      DO 6 I3=1,MAXN
      DO 6 I4=1,MAXN	  
      SUMX=P5(I1)+P5(I2)+P5(I3)+P5(I4)
      I5=1
   2  IF(I5-MAXN) 3,3,6
   3  IF(P5(I5)-SUMX) 5,4,6
   4  WRITE(*,300) I1,I2,I3,I4,I5
      STOP
   5  I5=I5+1
      GOTO 2
   6  CONTINUE
 300  FORMAT(5(1X,I3))
      END
Task: Euler's sum of powers conjecture






PHP: <?php

function eulers_sum_of_powers () {
	$max_n = 250;
	$pow_5 = array();
	$pow_5_to_n = array();
	for ($p = 1; $p <= $max_n; $p ++) {
		$pow5 = pow($p, 5);
		$pow_5 [$p] = $pow5;
		$pow_5_to_n[$pow5] = $p;
	}
	foreach ($pow_5 as $n_0 => $p_0) {
		foreach ($pow_5 as $n_1 => $p_1) {
			if ($n_0 < $n_1) continue;
			foreach ($pow_5 as $n_2 => $p_2) {
				if ($n_1 < $n_2) continue;
				foreach ($pow_5 as $n_3 => $p_3) {
					if ($n_2 < $n_3) continue;
					$pow_5_sum = $p_0 + $p_1 + $p_2 + $p_3;
					if (isset($pow_5_to_n[$pow_5_sum])) {
						return array($n_0, $n_1, $n_2, $n_3, $pow_5_to_n[$pow_5_sum]);
					}
				}
			}
		}
	}
}

list($n_0, $n_1, $n_2, $n_3, $y) = eulers_sum_of_powers();

echo "$n_0^5 + $n_1^5 + $n_2^5 + $n_3^5 = $y^5";

?>





Fortran: C EULER SUM OF POWERS CONJECTURE - FORTRAN IV
C FIND I1,I2,I3,I4,I5 : I1**5+I2**5+I3**5+I4**5=I5**5
      INTEGER I,P5(250),SUMX
      MAXN=250
      DO 1 I=1,MAXN
   1  P5(I)=I**5
      DO 6 I1=1,MAXN
      DO 6 I2=1,MAXN
      DO 6 I3=1,MAXN
      DO 6 I4=1,MAXN	  
      SUMX=P5(I1)+P5(I2)+P5(I3)+P5(I4)
      I5=1
   2  IF(I5-MAXN) 3,3,6
   3  IF(P5(I5)-SUMX) 5,4,6
   4  WRITE(*,300) I1,I2,I3,I4,I5
      STOP
   5  I5=I5+1
      GOTO 2
   6  CONTINUE
 300  FORMAT(5(1X,I3))
      END
Task: Euler's sum of powers conjecture






PHP: <?php

function eulers_sum_of_powers () {
	$max_n = 250;
	$pow_5 = array();
	$pow_5_to_n = array();
	for ($p = 1; $p <= $max_n; $p ++) {
		$pow5 = pow($p, 5);
		$pow_5 [$p] = $pow5;
		$pow_5_to_n[$pow5] = $p;
	}
	foreach ($pow_5 as $n_0 => $p_0) {
		foreach ($pow_5 as $n_1 => $p_1) {
			if ($n_0 < $n_1) continue;
			foreach ($pow_5 as $n_2 => $p_2) {
				if ($n_1 < $n_2) continue;
				foreach ($pow_5 as $n_3 => $p_3) {
					if ($n_2 < $n_3) continue;
					$pow_5_sum = $p_0 + $p_1 + $p_2 + $p_3;
					if (isset($pow_5_to_n[$pow_5_sum])) {
						return array($n_0, $n_1, $n_2, $n_3, $pow_5_to_n[$pow_5_sum]);
					}
				}
			}
		}
	}
}

list($n_0, $n_1, $n_2, $n_3, $y) = eulers_sum_of_powers();

echo "$n_0^5 + $n_1^5 + $n_2^5 + $n_3^5 = $y^5";

?>
Task: Euler's sum of powers conjecture






PHP: <?php

function eulers_sum_of_powers () {
	$max_n = 250;
	$pow_5 = array();
	$pow_5_to_n = array();
	for ($p = 1; $p <= $max_n; $p ++) {
		$pow5 = pow($p, 5);
		$pow_5 [$p] = $pow5;
		$pow_5_to_n[$pow5] = $p;
	}
	foreach ($pow_5 as $n_0 => $p_0) {
		foreach ($pow_5 as $n_1 => $p_1) {
			if ($n_0 < $n_1) continue;
			foreach ($pow_5 as $n_2 => $p_2) {
				if ($n_1 < $n_2) continue;
				foreach ($pow_5 as $n_3 => $p_3) {
					if ($n_2 < $n_3) continue;
					$pow_5_sum = $p_0 + $p_1 + $p_2 + $p_3;
					if (isset($pow_5_to_n[$pow_5_sum])) {
						return array($n_0, $n_1, $n_2, $n_3, $pow_5_to_n[$pow_5_sum]);
					}
				}
			}
		}
	}
}

list($n_0, $n_1, $n_2, $n_3, $y) = eulers_sum_of_powers();

echo "$n_0^5 + $n_1^5 + $n_2^5 + $n_3^5 = $y^5";

?>






Ada: with Ada.Text_IO;

procedure Sum_Of_Powers is
   
   type Base is range 0 .. 250; 
   type Num is range 0 .. 4*(250**5); 
   subtype Fit is Num range 0 .. 250**5; 
   
   Modulus: constant Num := 254;
   type Modular is mod Modulus;
 
   type Result_Type is array(1..5) of Base; 
  
   type Y_Type is array(Modular) of Base;
   type Y_Sum_Type is array(Modular) of Fit;

   Y_Sum: Y_Sum_Type := (others => 0);  
   Y: Y_Type := (others => 0);
      
      
      
      
      
   
   function Compute_Coefficients return Result_Type is  
   
      Sum_A: Fit;
      Sum_AB, Sum_ABC, Sum_ABCD: Num;
      Short: Modular;
      
   begin
      for A in Base(0) .. 246 loop
         Sum_A := Num(A) ** 5;
         for B in A .. 247 loop
            Sum_AB := Sum_A + (Num(B) ** 5);
            for C in Base'Max(B,1) .. 248 loop 
               Sum_ABC := Sum_AB + (Num(C) ** 5);
               for D in C .. 249 loop
                  Sum_ABCD := Sum_ABC + (Num(D) ** 5);
                  Short    := Modular(Sum_ABCD mod Modulus);
                  if Y_Sum(Short) = Sum_ABCD then
                     return A & B & C & D & Y(Short);
                  end if;
               end loop;
            end loop;
         end loop;
      end loop;
      return 0 & 0 & 0 & 0 & 0;
   end Compute_Coefficients;

   Tmp: Fit;
   ABCD_Y: Result_Type;

begin 

   
   for I in Base(0) .. 250 loop
      Tmp := Num(I)**5;
      if Y_Sum(Modular(Tmp mod Modulus)) /= 0 then 
         raise Program_Error with "Collision: Change Modulus and recompile!";
      else
         Y_Sum(Modular(Tmp mod Modulus)) := Tmp;
         Y(Modular(Tmp mod Modulus)) := I;
      end if;
   end loop;
   
   
   ABCD_Y := Compute_Coefficients;

   
   for Number of ABCD_Y loop
      Ada.Text_IO.Put(Base'Image(Number));
   end loop;
   Ada.Text_IO.New_Line;
   
end Sum_Of_Powers;
Task: Strip control codes and extended characters from a string



C#: using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RosettaCode
{
    class Program
    {
        static void Main(string[] args)
        {
            string test = "string of ☺☻♥♦⌂, may include control characters and other ilk.♫☼§►↔◄";
            Console.WriteLine("Original: {0}", test);
            Console.WriteLine("Stripped of control codes: {0}", StripControlChars(test));
            Console.WriteLine("Stripped of extended: {0}", StripExtended(test));
        }

        static string StripControlChars(string arg)
        {
            char[] arrForm = arg.ToCharArray();
            StringBuilder buffer = new StringBuilder(arg.Length);
            
            foreach(char ch in arrForm)
                if (!Char.IsControl(ch)) buffer.Append(ch);

            return buffer.ToString();
        }

        static string StripExtended(string arg)
        {
            StringBuilder buffer = new StringBuilder(arg.Length); 
            foreach(char ch in arg)
            {
                UInt16 num = Convert.ToUInt16(ch);
                
                if((num >= 32u) && (num <= 126u)) buffer.Append(ch);
            }
            return buffer.ToString();
        }
    }
}









Ada: with Ada.Text_IO;

procedure Strip_ASCII is

   Full: String := 'a' & Character'Val(11) & 'b' & Character'Val(166) &
                   'c' & Character'Val(127) & Character'Val(203) &
                   Character'Val(202) & "de";
   
   
   

   function Filter(S:     String;
                   From:  Character := ' ';
                   To:    Character := Character'Val(126);
                   Above: Character := Character'Val(127)) return String is
   begin
      if S'Length = 0 then
         return "";
      elsif (S(S'First) >= From and then S(S'First) <= To) or else S(S'First) > Above then
         return S(S'First) & Filter(S(S'First+1 .. S'Last), From, To, Above);
      else
         return Filter(S(S'First+1 .. S'Last), From, To, Above);
      end if;
   end Filter;

   procedure Put_Line(Text, S: String) is
   begin
      Ada.Text_IO.Put_Line(Text & " """ & S & """, Length:" & Integer'Image(S'Length));
   end Put_Line;

begin
   Put_Line("The full string :", Full);
   Put_Line("No Control Chars:", Filter(Full)); 
   Put_Line("Neither_Extended:", Filter(Full, Above => Character'Last)); 
end Strip_ASCII;
Task: Strip control codes and extended characters from a string

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

#define MAXBUF 256  
#define STR_SZ 100   



int ascii (const unsigned char c);

int ascii_ext (const unsigned char c);

unsigned char* strip(unsigned char* str, const size_t n, int ext );


 
int ascii (const unsigned char c) 
{  
  unsigned char min = 32;   
  unsigned char max = 126;  

  if ( c>=min && c<=max ) return 1;

  return 0;
} 


 
int ascii_ext (const unsigned char c) 
{  
  unsigned char min_ext = 128;   
  unsigned char max_ext = 255;

  if ( c>=min_ext && c<=max_ext )
       return 1;

  return 0;
} 




unsigned char* strip( unsigned char* str, const size_t n, int ext) 
{ 

  unsigned char buffer[MAXBUF] = {'\0'};

  size_t i = 0;  
  size_t j = 0;  

  size_t max = (n<MAXBUF)? n : MAXBUF -1;  

  while (i < max )
    {
      if ( (ext && ascii_ext(str[i]) ) ||  (ascii(str[i]) ) )    
	{
	  buffer[j++] = str[i]; 
	}      
      i++;
    }

  memset(str, '\0', max); 

  i = 0;               

  while( i < j)
    {
      str[i] = buffer[i]; 
      i++;
    }

  str[j] = '\0';  

  return str;  
}


int main( int argc, char** argv)
{
  enum {ASCII=0, EXT=1}; 

  unsigned int seed = 134529;  

  
  unsigned char badstring[STR_SZ] = {'\0'};
  unsigned char bs_2[STR_SZ]      = {'\0'};
 
  unsigned char* goodstring = NULL;
  unsigned char* goodstring_ext = NULL;

  size_t i = 0;

  srand(seed); 

  fprintf(stdout, "Original:\t" );

  
  for (i = 0; i < STR_SZ; i++)
    {
      badstring[i] = (unsigned char) ( rand () & (unsigned char)0xFF );
      fprintf(stdout, "%c", badstring[i] );
    }
  fprintf(stdout, "\n");

   
   memcpy(bs_2, badstring, STR_SZ * sizeof(unsigned char) ); 

   goodstring_ext = strip( badstring, STR_SZ, EXT); 

   fprintf(stdout, "\nEXT:\t%s\n" , goodstring_ext );

   goodstring = strip( bs_2, STR_SZ, ASCII); 
  
   fprintf(stdout, "\nASCII:\t%s\n" , goodstring );
  
return 0;
}











Ada: with Ada.Text_IO;

procedure Strip_ASCII is

   Full: String := 'a' & Character'Val(11) & 'b' & Character'Val(166) &
                   'c' & Character'Val(127) & Character'Val(203) &
                   Character'Val(202) & "de";
   
   
   

   function Filter(S:     String;
                   From:  Character := ' ';
                   To:    Character := Character'Val(126);
                   Above: Character := Character'Val(127)) return String is
   begin
      if S'Length = 0 then
         return "";
      elsif (S(S'First) >= From and then S(S'First) <= To) or else S(S'First) > Above then
         return S(S'First) & Filter(S(S'First+1 .. S'Last), From, To, Above);
      else
         return Filter(S(S'First+1 .. S'Last), From, To, Above);
      end if;
   end Filter;

   procedure Put_Line(Text, S: String) is
   begin
      Ada.Text_IO.Put_Line(Text & " """ & S & """, Length:" & Integer'Image(S'Length));
   end Put_Line;

begin
   Put_Line("The full string :", Full);
   Put_Line("No Control Chars:", Filter(Full)); 
   Put_Line("Neither_Extended:", Filter(Full, Above => Character'Last)); 
end Strip_ASCII;
Task: Strip control codes and extended characters from a string


C++: #include <string>
#include <iostream>
#include <algorithm>
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/casts.hpp>
#include <ctime>
#include <cstdlib>
using namespace boost::lambda ;

struct MyRandomizer {
   char operator( )( ) {
      return static_cast<char>( rand( ) % 256 ) ;
   }
} ;

std::string deleteControls ( std::string startstring ) {
   std::string noControls( "                                        " ) ;
   
   std::remove_copy_if( startstring.begin( ) , startstring.end( ) , noControls.begin( ) ,
	 ll_static_cast<int>( _1 ) < 32 && ll_static_cast<int>( _1 ) == 127 ) ;
   return noControls ;
}

std::string deleteExtended( std::string startstring ) {
   std::string noExtended ( "                                        " ) ;
   std::remove_copy_if( startstring.begin( ) , startstring.end( ) , noExtended.begin( ) ,
	 ll_static_cast<int>( _1 ) > 127 || ll_static_cast<int>( _1 ) < 32 ) ;
   return noExtended ;
}
   
int main( ) {
   std::string my_extended_string ;
   for ( int i = 0 ; i < 40 ; i++ ) 
      my_extended_string.append( " " ) ;
   srand( time( 0 ) ) ;
   std::generate_n( my_extended_string.begin( ) , 40 , MyRandomizer( ) ) ;
   std::string no_controls( deleteControls( my_extended_string ) ) ;
   std::string no_extended ( deleteExtended( my_extended_string ) ) ;
   std::cout << "string with all characters: " << my_extended_string << std::endl ;
   std::cout << "string without control characters: " << no_controls << std::endl ;
   std::cout << "string without extended characters: " << no_extended << std::endl ;
   return 0 ;
}










Ada: with Ada.Text_IO;

procedure Strip_ASCII is

   Full: String := 'a' & Character'Val(11) & 'b' & Character'Val(166) &
                   'c' & Character'Val(127) & Character'Val(203) &
                   Character'Val(202) & "de";
   
   
   

   function Filter(S:     String;
                   From:  Character := ' ';
                   To:    Character := Character'Val(126);
                   Above: Character := Character'Val(127)) return String is
   begin
      if S'Length = 0 then
         return "";
      elsif (S(S'First) >= From and then S(S'First) <= To) or else S(S'First) > Above then
         return S(S'First) & Filter(S(S'First+1 .. S'Last), From, To, Above);
      else
         return Filter(S(S'First+1 .. S'Last), From, To, Above);
      end if;
   end Filter;

   procedure Put_Line(Text, S: String) is
   begin
      Ada.Text_IO.Put_Line(Text & " """ & S & """, Length:" & Integer'Image(S'Length));
   end Put_Line;

begin
   Put_Line("The full string :", Full);
   Put_Line("No Control Chars:", Filter(Full)); 
   Put_Line("Neither_Extended:", Filter(Full, Above => Character'Last)); 
end Strip_ASCII;
Task: Strip control codes and extended characters from a string




Go: package main

import (
	"golang.org/x/text/transform"
	"golang.org/x/text/unicode/norm"
	"fmt"
	"strings"
)


func stripCtlFromBytes(str string) string {
	b := make([]byte, len(str))
	var bl int
	for i := 0; i < len(str); i++ {
		c := str[i]
		if c >= 32 && c != 127 {
			b[bl] = c
			bl++
		}
	}
	return string(b[:bl])
}

func stripCtlAndExtFromBytes(str string) string {
	b := make([]byte, len(str))
	var bl int
	for i := 0; i < len(str); i++ {
		c := str[i]
		if c >= 32 && c < 127 {
			b[bl] = c
			bl++
		}
	}
	return string(b[:bl])
}


func stripCtlFromUTF8(str string) string {
	return strings.Map(func(r rune) rune {
		if r >= 32 && r != 127 {
			return r
		}
		return -1
	}, str)
}

func stripCtlAndExtFromUTF8(str string) string {
	return strings.Map(func(r rune) rune {
		if r >= 32 && r < 127 {
			return r
		}
		return -1
	}, str)
}





func stripCtlAndExtFromUnicode(str string) string {
	isOk := func(r rune) bool {
		return r < 32 || r >= 127
	}
	
	t := transform.Chain(norm.NFKD, transform.RemoveFunc(isOk))
	
	
	
	str, _, _ = transform.String(t, str)
	return str
}

const src = "déjà vu" + 
	"\n\000\037 \041\176\177\200\377\n" + 
	"as⃝df̅" 

func main() {
	fmt.Println("source text:")
	fmt.Println(src)
	fmt.Println("\nas bytes, stripped of control codes:")
	fmt.Println(stripCtlFromBytes(src))
	fmt.Println("\nas bytes, stripped of control codes and extended characters:")
	fmt.Println(stripCtlAndExtFromBytes(src))
	fmt.Println("\nas UTF-8, stripped of control codes:")
	fmt.Println(stripCtlFromUTF8(src))
	fmt.Println("\nas UTF-8, stripped of control codes and extended characters:")
	fmt.Println(stripCtlAndExtFromUTF8(src))
	fmt.Println("\nas decomposed and stripped Unicode:")
	fmt.Println(stripCtlAndExtFromUnicode(src))
}








Ada: with Ada.Text_IO;

procedure Strip_ASCII is

   Full: String := 'a' & Character'Val(11) & 'b' & Character'Val(166) &
                   'c' & Character'Val(127) & Character'Val(203) &
                   Character'Val(202) & "de";
   
   
   

   function Filter(S:     String;
                   From:  Character := ' ';
                   To:    Character := Character'Val(126);
                   Above: Character := Character'Val(127)) return String is
   begin
      if S'Length = 0 then
         return "";
      elsif (S(S'First) >= From and then S(S'First) <= To) or else S(S'First) > Above then
         return S(S'First) & Filter(S(S'First+1 .. S'Last), From, To, Above);
      else
         return Filter(S(S'First+1 .. S'Last), From, To, Above);
      end if;
   end Filter;

   procedure Put_Line(Text, S: String) is
   begin
      Ada.Text_IO.Put_Line(Text & " """ & S & """, Length:" & Integer'Image(S'Length));
   end Put_Line;

begin
   Put_Line("The full string :", Full);
   Put_Line("No Control Chars:", Filter(Full)); 
   Put_Line("Neither_Extended:", Filter(Full, Above => Character'Last)); 
end Strip_ASCII;
Task: Strip control codes and extended characters from a string





Java: import java.util.function.IntPredicate;

public class StripControlCodes {

    public static void main(String[] args) {
        String s = "\u0000\n abc\u00E9def\u007F";
        System.out.println(stripChars(s, c -> c > '\u001F' && c != '\u007F'));
        System.out.println(stripChars(s, c -> c > '\u001F' && c < '\u007F'));
    }

    static String stripChars(String s, IntPredicate include) {
        return s.codePoints().filter(include::test).collect(StringBuilder::new,
                StringBuilder::appendCodePoint, StringBuilder::append).toString();
    }
}







Ada: with Ada.Text_IO;

procedure Strip_ASCII is

   Full: String := 'a' & Character'Val(11) & 'b' & Character'Val(166) &
                   'c' & Character'Val(127) & Character'Val(203) &
                   Character'Val(202) & "de";
   
   
   

   function Filter(S:     String;
                   From:  Character := ' ';
                   To:    Character := Character'Val(126);
                   Above: Character := Character'Val(127)) return String is
   begin
      if S'Length = 0 then
         return "";
      elsif (S(S'First) >= From and then S(S'First) <= To) or else S(S'First) > Above then
         return S(S'First) & Filter(S(S'First+1 .. S'Last), From, To, Above);
      else
         return Filter(S(S'First+1 .. S'Last), From, To, Above);
      end if;
   end Filter;

   procedure Put_Line(Text, S: String) is
   begin
      Ada.Text_IO.Put_Line(Text & " """ & S & """, Length:" & Integer'Image(S'Length));
   end Put_Line;

begin
   Put_Line("The full string :", Full);
   Put_Line("No Control Chars:", Filter(Full)); 
   Put_Line("Neither_Extended:", Filter(Full, Above => Character'Last)); 
end Strip_ASCII;
Task: Strip control codes and extended characters from a string







Python: stripped = lambda s: "".join(i for i in s if 31 < ord(i) < 127)

print(stripped("\ba\x00b\n\rc\fd\xc3"))





Ada: with Ada.Text_IO;

procedure Strip_ASCII is

   Full: String := 'a' & Character'Val(11) & 'b' & Character'Val(166) &
                   'c' & Character'Val(127) & Character'Val(203) &
                   Character'Val(202) & "de";
   
   
   

   function Filter(S:     String;
                   From:  Character := ' ';
                   To:    Character := Character'Val(126);
                   Above: Character := Character'Val(127)) return String is
   begin
      if S'Length = 0 then
         return "";
      elsif (S(S'First) >= From and then S(S'First) <= To) or else S(S'First) > Above then
         return S(S'First) & Filter(S(S'First+1 .. S'Last), From, To, Above);
      else
         return Filter(S(S'First+1 .. S'Last), From, To, Above);
      end if;
   end Filter;

   procedure Put_Line(Text, S: String) is
   begin
      Ada.Text_IO.Put_Line(Text & " """ & S & """, Length:" & Integer'Image(S'Length));
   end Put_Line;

begin
   Put_Line("The full string :", Full);
   Put_Line("No Control Chars:", Filter(Full)); 
   Put_Line("Neither_Extended:", Filter(Full, Above => Character'Last)); 
end Strip_ASCII;
Task: Strip control codes and extended characters from a string








VB: Function StripCtrlCodes(s)
	tmp = ""
	For i = 1 To Len(s)
		n = Asc(Mid(s,i,1))
		If (n >= 32 And n <= 126) Or n >=128 Then
			tmp = tmp & Mid(s,i,1)
		End If
	Next
	StripCtrlCodes = tmp	
End Function

Function StripCtrlCodesExtChrs(s)
	tmp = ""
	For i = 1 To Len(s)
		n = Asc(Mid(s,i,1))
		If n >= 32 And n <= 126 Then
			tmp = tmp & Mid(s,i,1)
		End If
	Next
	StripCtrlCodesExtChrs = tmp	
End Function

WScript.StdOut.Write "ab�cd�ef�gh�€" & " = " & StripCtrlCodes("ab�cd�ef�gh�€")
WScript.StdOut.WriteLine
WScript.StdOut.Write "ab�cd�ef�gh�ij†klð€" & " = " & StripCtrlCodesExtChrs("ab�cd�ef�gh�ij†klð€")
WScript.StdOut.WriteLine




Ada: with Ada.Text_IO;

procedure Strip_ASCII is

   Full: String := 'a' & Character'Val(11) & 'b' & Character'Val(166) &
                   'c' & Character'Val(127) & Character'Val(203) &
                   Character'Val(202) & "de";
   
   
   

   function Filter(S:     String;
                   From:  Character := ' ';
                   To:    Character := Character'Val(126);
                   Above: Character := Character'Val(127)) return String is
   begin
      if S'Length = 0 then
         return "";
      elsif (S(S'First) >= From and then S(S'First) <= To) or else S(S'First) > Above then
         return S(S'First) & Filter(S(S'First+1 .. S'Last), From, To, Above);
      else
         return Filter(S(S'First+1 .. S'Last), From, To, Above);
      end if;
   end Filter;

   procedure Put_Line(Text, S: String) is
   begin
      Ada.Text_IO.Put_Line(Text & " """ & S & """, Length:" & Integer'Image(S'Length));
   end Put_Line;

begin
   Put_Line("The full string :", Full);
   Put_Line("No Control Chars:", Filter(Full)); 
   Put_Line("Neither_Extended:", Filter(Full, Above => Character'Last)); 
end Strip_ASCII;
Task: Strip control codes and extended characters from a string

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

#define MAXBUF 256  
#define STR_SZ 100   



int ascii (const unsigned char c);

int ascii_ext (const unsigned char c);

unsigned char* strip(unsigned char* str, const size_t n, int ext );


 
int ascii (const unsigned char c) 
{  
  unsigned char min = 32;   
  unsigned char max = 126;  

  if ( c>=min && c<=max ) return 1;

  return 0;
} 


 
int ascii_ext (const unsigned char c) 
{  
  unsigned char min_ext = 128;   
  unsigned char max_ext = 255;

  if ( c>=min_ext && c<=max_ext )
       return 1;

  return 0;
} 




unsigned char* strip( unsigned char* str, const size_t n, int ext) 
{ 

  unsigned char buffer[MAXBUF] = {'\0'};

  size_t i = 0;  
  size_t j = 0;  

  size_t max = (n<MAXBUF)? n : MAXBUF -1;  

  while (i < max )
    {
      if ( (ext && ascii_ext(str[i]) ) ||  (ascii(str[i]) ) )    
	{
	  buffer[j++] = str[i]; 
	}      
      i++;
    }

  memset(str, '\0', max); 

  i = 0;               

  while( i < j)
    {
      str[i] = buffer[i]; 
      i++;
    }

  str[j] = '\0';  

  return str;  
}


int main( int argc, char** argv)
{
  enum {ASCII=0, EXT=1}; 

  unsigned int seed = 134529;  

  
  unsigned char badstring[STR_SZ] = {'\0'};
  unsigned char bs_2[STR_SZ]      = {'\0'};
 
  unsigned char* goodstring = NULL;
  unsigned char* goodstring_ext = NULL;

  size_t i = 0;

  srand(seed); 

  fprintf(stdout, "Original:\t" );

  
  for (i = 0; i < STR_SZ; i++)
    {
      badstring[i] = (unsigned char) ( rand () & (unsigned char)0xFF );
      fprintf(stdout, "%c", badstring[i] );
    }
  fprintf(stdout, "\n");

   
   memcpy(bs_2, badstring, STR_SZ * sizeof(unsigned char) ); 

   goodstring_ext = strip( badstring, STR_SZ, EXT); 

   fprintf(stdout, "\nEXT:\t%s\n" , goodstring_ext );

   goodstring = strip( bs_2, STR_SZ, ASCII); 
  
   fprintf(stdout, "\nASCII:\t%s\n" , goodstring );
  
return 0;
}