-
Jul 4th, 2011, 03:29 PM
#1
Pangram Tester
A pangram is one of those sentences like "The quick brown fox jumps over a lazy dog" which contains every letter of the English alphabet. For all I know they may exist in other languages too. They have a minor practical use: for showing off font examples. There is an art to writing a pangram which is as short as possible but still reads like a proper sentence. See here for more information and examples.
I was amusing myself trying to invent new pangrams on paper. Checking whether you haven't missed any letters is a bit of a chore. So I made a little program that does that automatically. The program also shows the number of letters in the pangram, and it has a button for saving your pangrams to a text file.
The form contains two text boxes; the top one is multiline and the second one is read-only. The code is pretty simple:
Here's the code for the form:
Code:
Public Class PangramTesterForm
Private _Alphabet As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Private _Punctuation As String = " .,-:;!?'""()[]{}/"
Private _Pangram As New System.Text.StringBuilder
Private Sub TextBox1_TextChanged(sender As Object, e As System.EventArgs) Handles TextBox1.TextChanged
Dim missingLetters As New System.Text.StringBuilder
_Pangram = New System.Text.StringBuilder(TextBox1.Text.ToUpper)
'Count letters excluding punctuation:
For Each ch As Char In _Punctuation
_Pangram.Replace(ch, "")
Next
lblCountLetters.Text = "Total number of letters = " & _Pangram.Length.ToString
'Check for missing letters:
For Each ch As Char In _Alphabet.ToCharArray
If Not _Pangram.ToString.Contains(ch) Then
missingLetters.Append(ch)
missingLetters.Append(" ")
End If
Next
TextBox2.Text = missingLetters.ToString
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
'Save the pangram to a file.
Using sfd As New SaveFileDialog
sfd.DefaultExt = "txt"
sfd.OverwritePrompt = False
If sfd.ShowDialog = Windows.Forms.DialogResult.OK Then
Using sw As New IO.StreamWriter(sfd.FileName, True)
sw.WriteLine(TextBox1.Text)
End Using
End If
End Using
End Sub
End Class
I hope this inspires some amusing new pangrams.
BB
Last edited by boops boops; Jul 4th, 2011 at 05:24 PM.
Reason: more punctuation added on suggestion of minitech
-
Jul 4th, 2011, 04:10 PM
#2
Re: Pangram Tester
Nice code, I'll try and make some interesting ones
Shouldn't you test punctuation as not being in the alphabet, instead of just a specific range? Or use Char.IsPunctuation? (I could decide to use parentheses, you know )
(Heh, I love this one: "Dwarf mobs quiz lynx.jpg, kvetch!" Perfect newspaper headline.)
Last edited by minitech; Jul 4th, 2011 at 04:14 PM.
-
Jul 4th, 2011, 05:13 PM
#3
Re: Pangram Tester
Originally Posted by minitech
Nice code, I'll try and make some interesting ones
Shouldn't you test punctuation as not being in the alphabet, instead of just a specific range? Or use Char.IsPunctuation? (I could decide to use parentheses, you know )
Youre right, using Char.IsPunctation or Not Char.IsLetter would probably be a better design. But for now I think I'll just edit the punctuation string to include some brackets and quotation marks. After all, we can't allow just anything, can we?
(Heh, I love this one: "Dwarf mobs quiz lynx.jpg, kvetch!" Perfect newspaper headline.)
The ultimate: a 26-letter pangram.
BB
-
Jul 5th, 2011, 12:45 AM
#4
Re: Pangram Tester
I tried...
VBForums, why? Quick! Tzar, placed a jinxed genie!
-
Jul 5th, 2011, 10:32 AM
#5
Re: Pangram Tester
Zany shed of quivering tin jukebox wigwams, I clap!
That's the best I can do so far. 41, no proper nouns.
In French:
Jo Paul, ayant ses cinq klaxons de gaz wolofs, m'a vraiment fait du bien hier.
60. I didn't do so well, and it's a really... odd use of grammatical elements in the middle that kind of hurts.
Last edited by minitech; Jul 5th, 2011 at 10:48 AM.
-
Jul 5th, 2011, 11:59 AM
#6
Re: Pangram Tester
Originally Posted by ForumAccount
I tried...
Nice one, ForumAccount. Special VBForums category pangrams, hm...
Originally Posted by minitech
That's the best I can do so far. 41, no proper nouns.
In French:
60. I didn't do so well, and it's a really... odd use of grammatical elements in the middle that kind of hurts.
Quivering tin jukebox wigwams? Pure Dadaist poetry, minitech! I was wondering about les pangrammes in French. Do we have to expand the alphabet to include all the accented letters, so there has to be at least one of each accented letter? Or just ignore accents?
Anyway, here's my latest creation, 32 letters:
Powder-crazy hex quits Viking film job.
Has a certain Hollywood decadence, don't you think?
BB
Last edited by boops boops; Jul 5th, 2011 at 12:04 PM.
-
Jul 5th, 2011, 12:57 PM
#7
Re: Pangram Tester
I thought accented letters were mostly the same letter, so I left them out. I'd definitely try to add them if w could be left out, though - it's so hard to fit in.
-
Jul 5th, 2011, 01:09 PM
#8
Re: Pangram Tester
Haha! 44:
Quel veuf misanthrope cajoleur de Kenya. Wagon, boxez!
It makes absolutely zero sense.
-
Mar 2nd, 2017, 03:38 PM
#9
Re: Pangram Tester
I stumbled across your Pangram contribution looking for a different contribution of yours altogether and asked myself whether or not I could make the code more concise, this is what I came up with:
Code:
Private Function IsPangram(ByVal input As String) As Boolean
Return input.ToCharArray().Distinct().Where(Function(c) Char.IsLetter(c)).Count() = 26
End Function
Essentially it does the following:
- Split up the String into a Char array
- Keep only unique values
- Keep only letter values
- Check if the count equals the length of the alphabet
-
Mar 2nd, 2017, 05:08 PM
#10
Re: Pangram Tester
Well, that is part of it.
Doesn't look like it returns which characters are missing, which is important if you're trying to create a pangram.
-
Mar 2nd, 2017, 05:34 PM
#11
Re: Pangram Tester
Originally Posted by passel
Well, that is part of it.
Doesn't look like it returns which characters are missing, which is important if you're trying to create a pangram.
True. Then I give you this:
Code:
Private Function IsPanagram(ByVal input As String, ByRef missingChars() As Char) As Boolean
Dim allLetters() As Char = "abcdefghijklmnopqrstuvwxyz".ToCharArray()
Dim visibleChars() As Char = input.ToLower().ToCharArray().Distinct().Where(Function(c) Char.IsLetter(c)).ToArray()
missingChars = allLetters.Where(Function(c) Array.IndexOf(visibleChars, c) = -1).ToArray()
Return missingChars.Length = 0
End Function
-
Mar 2nd, 2017, 09:16 PM
#12
Re: Pangram Tester
I figured you would.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|