Remove vowels from a string: Difference between revisions

m
 
(25 intermediate revisions by 18 users not shown)
Line 9:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">F exceptGlyphs(exclusions, s)
R s.filter(c -> c !C @exclusions).join(‘’)
 
Line 20:
in one approach to a problem in learning another.’
 
print(exceptGlyphs(‘eau’, txt))</langsyntaxhighlight>
 
{{out}}
Line 35:
=={{header|8080 Assembly}}==
 
<langsyntaxhighlight lang="8080asm"> org 100h
jmp demo
;;; Remove the vowels from the $-terminated string at [DE]
Line 65:
mvi c,9 ; Print using CP/M
jmp 5
string: db 'THE QUICK BROWN FOX jumps over the lazy dog$'</langsyntaxhighlight>
 
{{out}}
Line 72:
 
=={{header|Action!}}==
<langsyntaxhighlight Actionlang="action!">BYTE FUNC IsVovel(CHAR c)
CHAR ARRAY vovels="AEIOUaeiou"
BYTE i
Line 110:
Test("The Quick Brown Fox Jumped Over the Lazy Dog's Back")
Test("Action! is a programming language for Atari 8-bit computer.")
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Remove_vowels_from_a_string.png Screenshot from Atari 8-bit computer]
Line 126:
 
=={{header|Ada}}==
<langsyntaxhighlight Adalang="ada">with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
 
Line 156:
Put_Line (NV2);
end Main;
</syntaxhighlight>
</lang>
{{output}}
<pre>
Line 167:
 
=={{header|ALGOL 68}}==
<langsyntaxhighlight lang="algol68">BEGIN
# returns s with the vowels removed #
OP DEVOWEL = ( STRING s )STRING:
Line 191:
test devowel( "abcdefghijklmnoprstuvwxyz" );
test devowel( "Algol 68 Programming Language" )
END</langsyntaxhighlight>
{{out}}
<pre>
Line 202:
 
=={{header|APL}}==
<syntaxhighlight lang APL="apl">devowel ← ~∘'AaEeIiOoUu'</langsyntaxhighlight>
{{out}}
<pre> devowel 'THE QUICK BROWN FOX jumps over the lazy dog'
Line 217:
We can also improve productivity by using library functions whenever feasible.
 
<langsyntaxhighlight lang="applescript">------- REMOVE A DEFINED SUBSET OF GLYPHS FROM A TEXT ------
 
-- exceptGlyphs :: String -> String -> Bool
Line 324:
set my text item delimiters to dlm
s
end unlines</langsyntaxhighlight>
{{Out}}
<pre>Rostt Cod is progrmming chrstomthy sit.
Line 337:
As has been noted on the Discussion page, this is necessarily a parochial task which depends on the natural language involved being written with vowels and consonants and on what constitutes a vowel in its orthography. w and y are vowels in Welsh, but consonants in English, although y is often used as a vowel in English too, as it is in other languages. The code below demonstrates how AppleScript might remove the five English vowels and their diacritical forms from a Latinate text. AppleScript can be made to "ignore" diacriticals and case in string comparisons, but not to ignore ligatures or other variations which aren't strictly speaking diacriticals, such as ø. These would need to be included in the vowel list explicitly.
 
<langsyntaxhighlight lang="applescript">-- Bog-standard AppleScript global-search-and-replace handler.
-- searchText can be either a single string or a list of strings to be replaced with replacementText.
on replace(mainText, searchText, replacementText)
Line 363:
set devowelledText to replace(txt, {"a", "e", "i", "o", "u"}, "")
end ignoring
return devowelledText</langsyntaxhighlight>
 
{{output}}
<langsyntaxhighlight AppleScriptlang="applescript">"Th qck brwn fx jmps vr th lzy dg
L'œvr d'n lv
vn Dijk
Line 373:
Jř Blhlvk cndcts Mrtn
P c pn tk brzczy w gszcz?
Mhdv"</langsyntaxhighlight>
 
=={{header|Arturo}}==
 
<langsyntaxhighlight lang="rebol">str: "Remove vowels from a string"
 
print str -- split "aeiouAEIOU"</langsyntaxhighlight>
 
{{out}}
Line 386:
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight AutoHotkeylang="autohotkey">str := "The quick brown fox jumps over the lazy dog"
for i, v in StrSplit("aeiou")
str := StrReplace(str, v)
MsgBox % str</langsyntaxhighlight>
{{out}}
<pre>Th qck brwn fx jmps vr th lzy dg</pre>
===RegEx Version===
<langsyntaxhighlight AutoHotkeylang="autohotkey">str := "The quick brown fox jumps over the lazy dog"
MsgBox % str := RegExReplace(str, "i)[aeiou]")</langsyntaxhighlight>
{{out}}
<pre>Th qck brwn fx jmps vr th lzy dg</pre>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f REMOVE_VOWELS_FROM_A_STRING.AWK
BEGIN {
Line 413:
exit(0)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 422:
new: Th qck brwn fx jmps vr th lzy dg
</pre>
 
 
=={{header|BASIC}}==
==={{header|Applesoft BASIC}}===
<syntaxhighlight lang="gwbasic">S$ = "Remove a defined subset of glyphs from a string."</syntaxhighlight>
<syntaxhighlight lang="gwbasic">N$ = "": IF LEN (S$) THEN FOR I = 1 TO LEN (S$):C$ = MID$ (S$,I,1):K = ASC (C$):K$ = CHR$ (K - 32 * (K > 95)):V = 0: FOR C = 1 TO 5:V = V + ( MID$ ("AEIOU",C,1) = K$): NEXT C:N$ = N$ + MID$ (C$,V + 1): NEXT I: PRINT N$;</syntaxhighlight>
{{out}}
<pre>
Rmv dfnd sbst f glyphs frm strng.
</pre>
==={{header|BASIC256}}===
<syntaxhighlight lang="basic256">mensaje$ = "If Peter Piper picked a pack of pickled peppers" + " or how many pickled peppers did Peter Piper pick?"
textofinal$ = ""
 
for i = 1 to length(mensaje$)
c$ = mid(mensaje$,i,1)
begin case
case lower(c$) = "a" or lower(c$) = "e" or lower(c$) = "i" or lower(c$) = "o" or lower(c$) = "u"
continue for
else
textofinal$ += c$
end case
next i
 
print textofinal$
end</syntaxhighlight>
 
==={{header|PureBasic}}===
<syntaxhighlight lang="purebasic">OpenConsole()
mensaje.s = "If Peter Piper picked a pack of pickled peppers" + " or how many pickled peppers did Peter Piper pick?"
textofinal.s = ""
 
For i.i = 1 To Len(mensaje)
c.s = Mid(mensaje,i,1)
Select c
Case "a", "e", "i", "o", "u", "A", "E", "I", "O", "U"
Continue
Default
textofinal + c
EndSelect
Next i
 
PrintN(textofinal)
Input()
CloseConsole()</syntaxhighlight>
 
==={{header|QBasic}}===
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
<syntaxhighlight lang="qbasic">mensaje$ = "If Peter Piper picked a pack of pickled peppers" + ", how many pickled peppers did Peter Piper pick?"
textofinal$ = ""
 
for i = 1 to len(mensaje$)
c$ = mid$(mensaje$, i, 1)
select case c$
case "a", "e", "i", "o", "u", "A", "E", "I", "O", "U"
REM continue for
case else
textofinal$ = textofinal$ + c$
end select
next i
 
print textofinal$
end</syntaxhighlight>
 
==={{header|Yabasic}}===
<syntaxhighlight lang="yabasic">mensaje$ = "If Peter Piper picked a pack of pickled peppers" + " : case how many pickled peppers did Peter Piper pick?"
textofinal$ = ""
 
for i = 1 to len(mensaje$)
c$ = mid$(mensaje$,i,1)
switch c$
case "a" : case "e" : case "i" : case "o" : case "u" : case "A" : case "E" : case "I" : case "O" : case "U"
continue
default
textofinal$ = textofinal$ + c$
end switch
next i
 
print textofinal$
end</syntaxhighlight>
 
 
=={{header|BCPL}}==
<langsyntaxhighlight lang="bcpl">get "libhdr"
 
let vowel(c) = valof
Line 443 ⟶ 526:
 
let start() be
writes(devowel("THE QUICK BROWN FOX jumps over the lazy dog.*N"))</langsyntaxhighlight>
{{out}}
<pre>TH QCK BRWN FX jmps vr th lzy dg.</pre>
 
=={{header|BQN}}==
<syntaxhighlight lang="bqn">Devowel ← ¬∘∊⟜"AaEeIiOoUu"⊸/</syntaxhighlight>
 
=={{header|C}}==
{{trans|Go}}
<langsyntaxhighlight lang="c">#include <stdio.h>
 
void print_no_vowels(const char *s) {
Line 483 ⟶ 569:
test("C Programming Language");
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>Input : C Programming Language
Line 489 ⟶ 575:
 
=={{header|C#}}==
<langsyntaxhighlight lang="csharp">static string remove_vowels(string value)
{
var stripped = from c in value.ToCharArray()
Line 508 ⟶ 594:
test("CSharp Programming Language");
}
</syntaxhighlight>
</lang>
{{out}}
<pre>Input: CSharp Programming Language
Line 514 ⟶ 600:
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <algorithm>
#include <iostream>
 
Line 560 ⟶ 646:
test("C++ Programming Language");
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>Input : C++ Programming Language
Line 567 ⟶ 653:
=={{header|Common Lisp}}==
 
<langsyntaxhighlight lang="lisp">(defun vowel-p (c &optional (vowels "aeiou"))
(and (characterp c) (characterp (find c vowels :test #'char-equal))))
 
(defun remove-vowels (s)
(and (stringp s) (remove-if #'vowel-p s)))</langsyntaxhighlight>
 
=={{header|Cowgol}}==
<langsyntaxhighlight lang="cowgol">include "cowgol.coh";
include "strings.coh";
 
Line 604 ⟶ 690:
CopyString(str, &buf[0]); # make a copy of the string into writeable memory
Devowel(&buf[0]); # remove the vowels
print(&buf[0]); # print the result </langsyntaxhighlight>
 
{{out}}
Line 611 ⟶ 697:
 
=={{header|D}}==
<langsyntaxhighlight lang="d">import std.stdio;
 
void print_no_vowels(string s) {
Line 628 ⟶ 714:
void main() {
print_no_vowels("D Programming Language");
}</langsyntaxhighlight>
{{out}}
<pre>D Prgrmmng Lngg</pre>
Line 634 ⟶ 720:
=={{header|Delphi}}==
{{libheader| System.SysUtils}}
<syntaxhighlight lang="delphi">
<lang Delphi>
program Remove_vowels_from_a_string;
 
Line 667 ⟶ 753:
end.
 
</syntaxhighlight>
</lang>
 
{{out}}
Line 674 ⟶ 760:
After: Th qck brwn fx jmps vr th lzy dg
</pre>
 
=={{header|EasyLang}}==
<syntaxhighlight>
func$ rmv s$ .
for c$ in strchars s$
if strpos "AEIOUaeiou" c$ <> 0
c$ = ""
.
r$ &= c$
.
return r$
.
print rmv "The Quick Brown Fox Jumped Over the Lazy Dog's Back"
</syntaxhighlight>
 
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">
let stripVowels n=let g=set['a';'e';'i';'o';'u';'A';'E';'I';'O';'U'] in n|>Seq.filter(fun n->not(g.Contains n))|>Array.ofSeq|>System.String
printfn "%s" (stripVowels "Nigel Galloway")
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 686 ⟶ 786:
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">USING: formatting kernel sets ;
 
: without-vowels ( str -- new-str ) "aeiouAEIOU" without ;
 
"Factor Programming Language" dup without-vowels
" Input string: %s\nWithout vowels: %s\n" printf</langsyntaxhighlight>
{{out}}
<pre>
Line 699 ⟶ 799:
 
=={{header|Forth}}==
<langsyntaxhighlight lang="forth">: VOWELS ( -- add len ) S" aeiouAEIOU" ;
 
: VALIDATE ( char addr len -- 0|n) ROT SCAN NIP ; \ find char in string
Line 715 ⟶ 815:
THEN
LOOP
PAD COUNT ;</langsyntaxhighlight>
{{out}}
<pre>
Line 724 ⟶ 824:
 
=={{header|Fortran}}==
<langsyntaxhighlight lang="fortran">
program remove_vowels
implicit none
Line 749 ⟶ 849:
end subroutine print_no_vowels
end program remove_vowels
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 759 ⟶ 859:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight FreeBASIClang="freebasic">dim as string message = "If Peter Piper picked a pack of pickled peppers"+_
", how many pickled peppers did Peter Piper pick?"
dim as string outstr = "", c
Line 773 ⟶ 873:
next i
 
print outstr</langsyntaxhighlight>
 
=={{header|Free Pascal}}==
''See also [[#Pascal|Pascal]]''
{{libheader|strUtils}}
<syntaxhighlight lang="pascal">{$longStrings on}
uses
strUtils;
var
line: string;
c: char;
begin
readLn(line);
for c in ['A', 'E', 'I', 'O', 'U', 'a', 'e', 'i', 'o', 'u'] do
begin
line := delChars(line, c)
end;
writeLn(line)
end.</syntaxhighlight>
 
=={{header|Frink}}==
<syntaxhighlight lang="frink">s = """Rosetta Code is a programming chrestomathy site.
The idea is to present solutions to the same
task in as many different languages as possible,
to demonstrate how languages are similar and
different, and to aid a person with a grounding
in one approach to a problem in learning another."""
 
println[s =~ %s/[aeiou]//gi ]</syntaxhighlight>
{{out}}
<pre>
Rstt Cd s prgrmmng chrstmthy st.
Th d s t prsnt sltns t th sm
tsk n s mny dffrnt lnggs s pssbl,
t dmnstrt hw lnggs r smlr nd
dffrnt, nd t d prsn wth grndng
n n pprch t prblm n lrnng nthr.
</pre>
 
=={{header|Fōrmulæ}}==
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/Remove_vowels_from_a_string}}
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text. Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation &mdash;i.e. XML, JSON&mdash; they are intended for storage and transfer purposes more than visualization and edition.
 
'''Solution'''
Programs in Fōrmulæ are created/edited online in its [https://formulae.org website], However they run on execution servers. By default remote servers are used, but they are limited in memory and processing power, since they are intended for demonstration and casual use. A local server can be downloaded and installed, it has no limitations (it runs in your own computer). Because of that, example programs can be fully visualized and edited, but some of them will not run if they require a moderate or heavy computation/memory resources, and no local server is being used.
 
[[File:Fōrmulæ - Remove vowels from a string 01.png]]
In '''[https://formulae.org/?example=Remove_vowels_from_a_string this]''' page you can see the program(s) related to this task and their results.
 
[[File:Fōrmulæ - Remove vowels from a string 02.png]]
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">window 1, @"Remove vowels from a string"
 
local fn StringByRemovingVowels( string as CFStringRef ) as CFStringRef
end fn = fn ArrayComponentsJoinedByString( fn StringComponentsSeparatedByCharactersInSet( string, fn CharacterSetWithCharactersInString( @"aeiou" ) ), @"" )
 
print fn StringByRemovingVowels( @"The quick brown fox jumps over the lazy dog." )
print fn StringByRemovingVowels( @"FutureBasic is a great programming language!" )
 
HandleEvents</syntaxhighlight>
{{out}}
<pre>
Th qck brwn fx jmps vr th lzy dg.
FtrBsc s grt prgrmmng lngg!
</pre>
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 806 ⟶ 961:
fmt.Println("Input :", s)
fmt.Println("Output :", removeVowels(s))
}</langsyntaxhighlight>
 
{{out}}
Line 818 ⟶ 973:
Removing three specific Anglo-Saxon vowels from a text, using a general method which can apply to any specific subset of glyphs.
 
<langsyntaxhighlight lang="haskell">------ REMOVE A SPECIFIC SUBSET OF GLYPHS FROM A STRING ----
exceptGlyphs :: String -> String -> String
Line 835 ⟶ 990:
main :: IO ()
main = putStrLn $ exceptGlyphs "eau" txt</langsyntaxhighlight>
 
or, in terms of filter:
<lang haskell>exceptGlyphs :: String -> String -> String
exceptGlyphs = filter . flip notElem</lang>
 
{{Out}}
Line 848 ⟶ 999:
diffrnt, nd to id prson with gronding
in on pproch to problm in lrning nothr.</pre>
 
=={{header|J}}==
<syntaxhighlight lang="j">devowel =: -. & 'aeiouAEIOU'</syntaxhighlight>
 
=={{header|Java}}==
You can use the ''String.replaceAll'' method, which takes a regular expression as it's first argument.
<lang java>public static String removeVowelse(String str){
<syntaxhighlight lang="java">
"rosettacode.org".replaceAll("(?i)[aeiou]", "");
</syntaxhighlight>
<br />
Or
<syntaxhighlight lang="java">public static String removeVowelse(String str){
String re = "";
char c;
Line 859 ⟶ 1,019:
}
return re;
}</langsyntaxhighlight>
 
=={{header|JavaScript}}==
Line 867 ⟶ 1,027:
( ''Pace'' Jamie Zawinski, some people, when confronted with a problem, think "I know, I'll use '''parser combinators'''." )
 
<langsyntaxhighlight lang="javascript">(() => {
'use strict'
 
Line 1,130 ⟶ 1,290:
// main ---
return main();
})();</langsyntaxhighlight>
{{Out}}
<pre> Rostt Cod is progrmming chrstomthy sit.
Line 1,142 ⟶ 1,302:
but a filter is all we need here:
 
<langsyntaxhighlight lang="javascript">(() => {
'use strict';
 
Line 1,166 ⟶ 1,326:
// main ---
return main();
})();</langsyntaxhighlight>
{{Out}}
<pre> Rostt Cod is progrmming chrstomthy sit.
Line 1,174 ⟶ 1,334:
diffrnt, nd to id prson with gronding
in on pproch to problm in lrning nothr.</pre>
 
=={{header|Joy}}==
<syntaxhighlight lang="joy">DEFINE unvowel == ["AaEeIiOoUu" in not] filter.
 
"Remove ALL vowels from this input!" unvowel putchars.</syntaxhighlight>
{{out}}
<pre>Rmv LL vwls frm ths npt!</pre>
 
=={{header|jq}}==
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
<syntaxhighlight lang="sh">
<lang sh>
#!/bin/bash
 
Line 1,212 ⟶ 1,379:
 
input | jq -Rr --arg v "$vowels" 'gsub("[\($v)]+"; ""; "i")'
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,242 ⟶ 1,409:
=={{header|Julia}}==
Unicode sensitive, using the Raku version example text.
<langsyntaxhighlight lang="julia">const ALLVOWELS = Dict(ch => 1 for ch in Vector{Char}("AÀÁÂÃÄÅĀĂĄǺȀȂẠẢẤẦẨẪẬẮẰẲẴẶḀÆǼEȄȆḔḖḘḚḜẸẺẼẾỀỂỄỆĒĔĖĘĚÈÉÊËIȈȊḬḮỈỊĨĪĬĮİÌÍÎÏIJOŒØǾȌȎṌṎṐṒỌỎỐỒỔỖỘỚỜỞỠỢŌÒÓŎŐÔÕÖUŨŪŬŮŰŲÙÚÛÜȔȖṲṴṶṸṺỤỦỨỪỬỮỰ"))
const ALLVOWELSY = Dict(ch => 1 for ch in Vector{Char}("AÀÁÂÃÄÅĀĂĄǺȀȂẠẢẤẦẨẪẬẮẰẲẴẶḀÆǼEȄȆḔḖḘḚḜẸẺẼẾỀỂỄỆĒĔĖĘĚÈÉÊËIȈȊḬḮỈỊĨĪĬĮİÌÍÎÏIJOŒØǾȌȎṌṎṐṒỌỎỐỒỔỖỘỚỜỞỠỢŌÒÓŎŐÔÕÖUŨŪŬŮŰŲÙÚÛÜȔȖṲṴṶṸṺỤỦỨỪỬỮỰYẙỲỴỶỸŶŸÝ"))
 
Line 1,259 ⟶ 1,426:
println("Removing vowels from:\n$testtext\n becomes:\n",
String(filter(!isvowel, Vector{Char}(testtext))))
</langsyntaxhighlight>{{out}}
<pre>
Removing vowels from:
Line 1,280 ⟶ 1,447:
dctn shll b fr, t lst n th lmntry nd fndmntl stgs.
</pre>
 
=={{header|K}}==
{{works with|ngn/k}}
<syntaxhighlight lang=K>novowel: {x^"aeiouAEIOU"}
 
novowel"The Quick Brown Fox Jumped Over the Lazy Dog's Back"
"Th Qck Brwn Fx Jmpd vr th Lzy Dg's Bck"
</syntaxhighlight>
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">fun removeVowels(s: String): String {
val re = StringBuilder()
for (c in s) {
Line 1,298 ⟶ 1,473:
fun main() {
println(removeVowels("Kotlin Programming Language"))
}</langsyntaxhighlight>
{{out}}
<pre>Ktln Prgrmmng Lngg</pre>
 
=={{header|Lambdatalk}}==
<syntaxhighlight lang="scheme">
'{S.replace [aeiouy]* by in
Rosetta Code is a programming chrestomathy site.
The idea is to present solutions to the same
task in as many different languages as possible,
to demonstrate how languages are similar and
different, and to aid a person with a grounding
in one approach to a problem in learning another.}
 
-> Rstt Cd s prgrmmng chrstmth st. Th d s t prsnt sltns t th sm tsk n s mn dffrnt lnggs s pssbl, t dmnstrt hw lnggs r smlr nd dffrnt, nd t d prsn wth grndng n n pprch t prblm n lrnng nthr.
</syntaxhighlight>
 
=={{header|Lua}}==
<langsyntaxhighlight lang="lua">function removeVowels (inStr)
local outStr, letter = ""
local vowels = "AEIUOaeiou"
Line 1,318 ⟶ 1,506:
 
local testStr = "The quick brown fox jumps over the lazy dog"
print(removeVowels(testStr))</langsyntaxhighlight>
{{out}}
<pre>Th qck brwn fx jmps vr th lzy dg</pre>
 
 
 
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">StringReplace["The Quick Brown Fox Jumped Over the Lazy Dog's Back", (Alternatives @@ Characters["aeiou"]) -> ""]</langsyntaxhighlight>
{{out}}
<pre>Th Qck Brwn Fx Jmpd Ovr th Lzy Dg's Bck</pre>
 
=={{header|MATLAB}} / {{header|Octave}}==
<syntaxhighlight lang="matlab">
<lang Matlab>
function [result] = remove_vowels(text)
% http://rosettacode.org/wiki/Remove_vowels_from_a_string
Line 1,346 ⟶ 1,537:
%!test
%! assert(remove_vowels('The quick brown fox jumps over the lazy dog'),'Th qck brwn fx jmps vr th lzy dg')
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,355 ⟶ 1,546:
 
=={{header|Nim}}==
<langsyntaxhighlight Nimlang="nim">import strutils, sugar
 
const Vowels = {'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'}
Line 1,370 ⟶ 1,561:
const TestString = "The quick brown fox jumps over the lazy dog"
echo TestString
echo TestString.dup(removeVowels(Vowels))</langsyntaxhighlight>
 
{{out}}
<pre>The quick brown fox jumps over the lazy dog
Th qck brwn fx jmps vr th lzy dg</pre>
 
=={{header|OCaml}}==
<syntaxhighlight lang="ocaml">let remove_vowels s : string =
let not_vowel = Fun.negate (String.contains "AaEeIiOoUu") in
String.to_seq s |> Seq.filter not_vowel |> String.of_seq</syntaxhighlight>
 
=={{header|Pascal}}==
''See also [[#Delphi|Delphi]] or [[#Free Pascal|Free Pascal]]''<br/>
This program works with any ISO 7185 compliant compiler.
<syntaxhighlight lang="pascal">program removeVowelsFromString(input, output);
 
const
stringLength = 80;
 
type
stringIndex = 1..stringLength;
string = array[stringIndex] of char;
 
var
sourceIndex, destinationIndex: stringIndex;
line, disemvoweledLine: string;
vowels: set of char;
 
function lineHasVowels: Boolean;
var
sourceIndex: stringIndex;
vowelIndices: set of stringIndex;
begin
vowelIndices := [];
for sourceIndex := 1 to stringLength do
begin
if line[sourceIndex] in vowels then
begin
vowelIndices := vowelIndices + [sourceIndex]
end
end;
lineHasVowels := vowelIndices <> []
end;
 
begin
vowels := ['A', 'E', 'I', 'O', 'U', 'a', 'e', 'i', 'o', 'u'];
{ - - input - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
for destinationIndex := 1 to stringLength do
begin
line[destinationIndex] := ' ';
if not EOLn(input) then
begin
read(line[destinationIndex])
end
end;
{ - - processing - - - - - - - - - - - - - - - - - - - - - - - - - - - }
if lineHasVowels then
begin
destinationIndex := 1;
for sourceIndex := 1 to stringLength do
begin
if not (line[sourceIndex] in vowels) then
begin
disemvoweledLine[destinationIndex] := line[sourceIndex];
destinationIndex := destinationIndex + 1
end
end;
{ pad remaining characters in `disemvoweledLine` with spaces }
for destinationIndex := destinationIndex to stringLength do
begin
disemvoweledLine[destinationIndex] := ' '
end;
end
else
begin
disemvoweledLine := line
end;
{ - - output - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
for destinationIndex := 1 to stringLength do
begin
write(disemvoweledLine[destinationIndex])
end;
writeLn
end.</syntaxhighlight>
{{in}}
The quick brown fox jumps over the lazy dog.
{{out}}
Th qck brwn fx jmps vr th lzy dg.
----
{{works with|Extended Pascal}}
More convenient though is to use some Extended Pascal (ISO 10206) features:
<syntaxhighlight lang="pascal">program removeVowelsFromString(input, output);
const
vowels = ['A', 'E', 'I', 'O', 'U', 'a', 'e', 'i', 'o', 'u'];
var
i: integer;
{ Extended Pascal: `… value ''` initializes both variables with `''`. }
line, disemvoweledLine: string(80) value '';
 
begin
readLn(line);
for i := 1 to length(line) do
begin
if not (line[i] in vowels) then
begin
disemvoweledLine := disemvoweledLine + line[i]
end
end;
writeLn(disemvoweledLine)
end.</syntaxhighlight>
{{in}}
The quick brown fox jumps over the lazy dog.
{{out}}
Th qck brwn fx jmps vr th lzy dg.
 
=={{header|Perl}}==
Inspired by the Raku entry.
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use utf8;
Line 1,397 ⟶ 1,704:
my @vowels;
chr($_) =~ /[aæeiıoœu]/i and push @vowels, chr($_) for 0x20 .. 0x1ff;
print NFD($_) =~ /@{[join '|', @vowels]}/ ? ' ' : $_ for split /(\X)/, $text;</langsyntaxhighlight>
{{out}}
<pre>N rw g n, c l nd c, G rm n, T rk sh, Fr nch, Sp n sh, ngl sh:
Line 1,409 ⟶ 1,716:
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">constant</span> <span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"Phix Programming Language"</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Input : %s\nOutput : %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">s</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">filter</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"out"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"aeiouAEIUO"</span><span style="color: #0000FF;">)})</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 1,419 ⟶ 1,726:
</pre>
If you want something a bit more like Julia/Raku, the following should work, but you have to provide your own vowel-set, or nick/merge from Julia/REXX
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
Line 1,444 ⟶ 1,751:
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%s\n"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">remove_vowels</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">))</span>
<!--</langsyntaxhighlight>-->
(output deliberately not shown due to windows console effects, but it is the same as Raku, or Julia with the alternate find/replace line.)
 
=={{header|Picat}}==
<syntaxhighlight lang="picat">main =>
println("The Quick Brown Fox Jumped Over the Lazy Dog's Back".remove_vowels),
println("Picat programming language".remove_vowels).
 
remove_vowels(S) = [C : C in S, not membchk(C,"AEIOUaeiou")].</syntaxhighlight>
 
{{out}}
<pre>Th Qck Brwn Fx Jmpd vr th Lzy Dg's Bck
Pct prgrmmng lngg</pre>
 
=={{header|Prolog}}==
Line 1,452 ⟶ 1,770:
 
 
<syntaxhighlight lang="prolog">
<lang Prolog>
:- system:set_prolog_flag(double_quotes,chars) .
 
Line 1,489 ⟶ 1,807:
lists:member(CHAR,"AEIOUaeiouüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜáíóúªºαΩ")
.
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,515 ⟶ 1,833:
 
{{works with|Python|3.7|}}
<langsyntaxhighlight lang="python">'''Remove a defined subset of glyphs from a string'''
 
 
Line 1,550 ⟶ 1,868:
# MAIN ---
if __name__ == '__main__':
main()</langsyntaxhighlight>
{{Out}}
<pre> Rostt Cod is progrmming chrstomthy sit.
Line 1,561 ⟶ 1,879:
===One liner===
Well, almost........
<syntaxhighlight lang="python">
<lang Python>
txt = '''
Rosetta Code is a programming chrestomathy site.
Line 1,571 ⟶ 1,889:
 
print(''.join(list(filter(lambda a: a not in "aeiou",txt))))
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,583 ⟶ 1,901:
 
=={{header|Quackery}}==
<langsyntaxhighlight Quackerylang="quackery">[ 0 $ "AEIOUaeiou"
witheach
[ bit | ] ] constant is vowels ( --> f )
Line 1,594 ⟶ 1,912:
$ '"Beautiful coquettes are quacks of love."'
$ ' -- Francois De La Rochefoucauld' join
disemvowel echo$</langsyntaxhighlight>
 
'''Output:'''
Line 1,612 ⟶ 1,930:
Strings from http://mylanguages.org/. No affiliation, but it's a nice resource. (note: these are not all the same sentence but are all from the same paragraph. They frankly were picked based on their vowel load.)
 
<syntaxhighlight lang="raku" perl6line>my @vowels = (0x20 .. 0x2fff).map: { .chr if .chr.samemark('x') ~~ m:i/<[aæeiıoœu]>/ }
 
my $text = q:to/END/;
Line 1,625 ⟶ 1,943:
END
 
put $text.subst(/@vowels/, ' ', :g);</langsyntaxhighlight>
{{out}}
<pre>N rw g n, c l nd c, G rm n, T rk sh, Fr nch, Sp n sh, ngl sh:
Line 1,641 ⟶ 1,959:
=== using the TRANSLATE BIF ===
This REXX version uses the &nbsp; '''translate''' &nbsp; BIF which works faster for longer strings as there is no character-by-character manipulation.
<langsyntaxhighlight lang="rexx">/*REXX program removes vowels (both lowercase and uppercase and accented) from a string.*/
parse arg x /*obtain optional argument from the CL.*/
if x='' | x="," then x= 'REXX Programming Language' /*Not specified? Then use default*/
Line 1,651 ⟶ 1,969:
y= space(translate(y, , vowels), 0) /*trans. vowels──►blanks, elide blanks.*/
y= translate(y, , q) /*trans the Q characters back to blanks*/
say 'output string: ' y /*stick a fork in it, we're all done. */</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default input:}}
<pre>
Line 1,660 ⟶ 1,978:
=== using character eliding ===
This REXX version uses a character-by-character manipulation and should be easier to understand.
<langsyntaxhighlight lang="rexx">/*REXX program removes vowels (both lowercase and uppercase and accented) from a string.*/
parse arg x /*obtain optional argument from the CL.*/
if x='' | x="," then x= 'REXX Programming Language' /*Not specified? Then use default*/
Line 1,674 ⟶ 1,992:
 
x= substr(x, 2) /*elide the prefixed dummy character. */
say 'output string: ' x /*stick a fork in it, we're all done. */</langsyntaxhighlight>
{{out|output|text=&nbsp; is identical to the 1<sup>st</sup> REXX version.}} <br><br>
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
load "stdlib.ring"
str = "Ring Programming Language"
Line 1,688 ⟶ 2,006:
next
see "String without vowels: " + str + nl
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,694 ⟶ 2,012:
String without vowels: Rng Prgrmmng Lngg
</pre>
=={{header|RPL}}==
≪ "AEIOUaeiou" → string vowels
≪ "" 1 string SIZE '''FOR''' j
string j DUP SUB
'''IF''' vowels OVER POS '''THEN''' DROP '''ELSE''' + '''END'''
'''NEXT'''
≫ ≫ ''''NOVWL'''' STO
{{in}}
<pre>
"This is a difficult sentence to pronounce" NOVWL
</pre>
{{out}}
<pre>
1: "Ths s dffclt sntnc t prnnc"
</pre>
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">
p "Remove vowels from a string".delete("aeiouAEIOU") # => "Rmv vwls frm strng"
</syntaxhighlight>
</lang>
 
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">
fn remove_vowels(str: String) -> String {
let vowels = "aeiouAEIOU";
Line 1,721 ⟶ 2,055:
println!("{}", remove_vowels(intro));
}
</syntaxhighlight>
</lang>
Output :
<pre>
Line 1,727 ⟶ 2,061:
Frrs, th crb, s th nffcl msct f th Rst Prgrmmng Lngg
</pre>
 
=={{header|sed}}==
<syntaxhighlight lang="sed">s/[AaEeIiOoUu]//g</syntaxhighlight>
 
=={{header|Smalltalk}}==
<langsyntaxhighlight lang="smalltalk">in := 'The balloon above harsh waters of programming languages, is the mascot of Smalltalk'.
out := in reject:[:ch | ch isVowel].
in printCR.
out printCR.</langsyntaxhighlight>
{{out}}
<pre>The balloon above harsh harsh waters of programming languages, is the mascot of Smalltalk
Line 1,738 ⟶ 2,075:
 
As usual, there are many alternative ways to do this:
<langsyntaxhighlight lang="smalltalk">out := in reject:#isVowel. " cool: symbols understand value: "
 
out := in select:[:ch | ch isVowel not].
Line 1,752 ⟶ 2,089:
ch isVowel ifFalse:[ s nextPut:ch ]
]]
</syntaxhighlight>
</lang>
 
=={{header|Standard ML}}==
<langsyntaxhighlight lang="sml">fun isVowel c =
CharVector.exists (fn v => c = v) "AaEeIiOoUu"
 
Line 1,763 ⟶ 2,100:
val str = "LOREM IPSUM dolor sit amet\n"
val () = print str
val () = print (removeVowels str)</langsyntaxhighlight>
{{out}}
<pre>LOREM IPSUM dolor sit amet
Line 1,769 ⟶ 2,106:
 
=={{header|Swift}}==
<langsyntaxhighlight lang="swift">func isVowel(_ char: Character) -> Bool {
switch (char) {
case "a", "A", "e", "E", "i", "I", "o", "O", "u", "U":
Line 1,784 ⟶ 2,121:
let str = "The Swift Programming Language"
print(str)
print(removeVowels(string: str))</langsyntaxhighlight>
 
{{out}}
Line 1,793 ⟶ 2,130:
 
=={{header|Visual Basic .NET}}==
<langsyntaxhighlight lang="vbnet">Imports System.Text
 
Module Module1
Line 1,823 ⟶ 2,160:
End Sub
 
End Module</langsyntaxhighlight>
{{out}}
<pre>Input : Visual Basic .NET
Output : Vsl Bsc .NT</pre>
 
=={{header|V (Vlang)}}==
{{trans|AutoHotkey}}
 
<syntaxhighlight lang="v (vlang)">fn main() {
mut str := 'The quick brown fox jumps over the lazy dog'
for val in 'aeiou'.split('') {str = str.replace(val,'')}
println(str)
}</syntaxhighlight>
 
{{out}}
<pre>
Th qck brwn fx jmps vr th lzy dg
</pre>
 
=={{header|Wren}}==
<langsyntaxhighlight ecmascriptlang="wren">var removeVowels = Fn.new { |s| s.where { |c| !"aeiouAEIOU".contains(c) }.join() }
 
var s = "Wren Programming Language"
System.print("Input : %(s)")
System.print("Output : %(removeVowels.call(s))")</langsyntaxhighlight>
 
{{out}}
Line 1,842 ⟶ 2,193:
 
=={{header|XBS}}==
<langsyntaxhighlight lang="xbs">func RemoveVowels(x:string):string{
set Vowels:array="aeiou"::split();
set nx:string="";
Line 1,856 ⟶ 2,207:
}
 
log(RemoveVowels("Hello, world!"));</langsyntaxhighlight>
{{out}}
<pre>
Line 1,863 ⟶ 2,214:
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">string 0; \make strings zero-terminated
 
func Disemvowel(S); \remove vowels from string
Line 1,877 ⟶ 2,228:
];
 
Text(0, Disemvowel("pack my box with FIVE DOZEN LIQUOR JUGS!"))</langsyntaxhighlight>
 
Output:
Line 1,885 ⟶ 2,236:
 
=={{header|XProfan}}==
<syntaxhighlight lang="xprofan">cls
<lang XProfan>cls
Set("RegEx",1)
Var string e = "The quick brown fox jumps over the lazy dog"
Var string a = Translate$(e,"(?i)[aeiou]","")
MessageBox("Input : "+e+"\nOutput: "+a,"Remove vowels",1)
End</langsyntaxhighlight>
{{out}}
<pre>
1,983

edits