comp.lang.ada
 help / color / mirror / Atom feed
From: Trish Cayetano <trishacayetano@gmail.com>
Subject: How to check if letters are in a string?
Date: Sat, 18 Jul 2015 02:00:38 -0700 (PDT)
Date: 2015-07-18T02:00:38-07:00	[thread overview]
Message-ID: <53a16384-fa63-479c-9421-553683dd6009@googlegroups.com> (raw)

Hi, 

How do you check if (exact number of) letters are in a string? 

1. This example should PASS because every letter is found in the string
LETTERS: HID
STRING:  HIDDEN

2. This example should FAIL because the letters contain 2 N's but the string only has 1 N. 
LETTERS: NINE
STRING:  HIDDEN


Pangram doesn't seem to be a solution... because it considers #2 above as PASS.
This is because pangrams check for AT LEAST one letter (this means, it considers a pangram even if the letter is a duplicate)


Is there another way how to check if (exact number of) letters are in a string? 
Thank you very much!


====
Here is the sample code: 

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Maps; use Ada.Strings.Maps;
with Ada.Characters.Handling; use Ada.Characters.Handling;
procedure main is
 
	function ispangram(txt: String) return Boolean is
		lowtxt : String := To_Lower(txt);
		letset,txtset : Character_Set;
		begin
		letset := To_Set("nine");
		txtset := To_Set(lowtxt);
		return (letset-txtset)=Null_Set;
	end ispangram;
 
begin
put_line(Boolean'Image(ispangram("hidden")));

end main;

============================================
OUTPUT: 

C:\Users\a0284014\Desktop\ada\pangram\obj\main
TRUE

[2015-07-18 16:52:42] process terminated successfully, elapsed time: 00.37s

             reply	other threads:[~2015-07-18  9:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-18  9:00 Trish Cayetano [this message]
2015-07-18 10:23 ` How to check if letters are in a string? Nasser M. Abbasi
2015-07-18 10:52   ` Trish Cayetano
2015-07-18 11:07   ` Simon Clubley
2015-07-18 11:36 ` Björn Lundin
2015-07-18 12:48   ` Trish Cayetano
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox