comp.lang.ada
 help / color / mirror / Atom feed
* How to check if letters are in a string?
@ 2015-07-18  9:00 Trish Cayetano
  2015-07-18 10:23 ` Nasser M. Abbasi
  2015-07-18 11:36 ` Björn Lundin
  0 siblings, 2 replies; 6+ messages in thread
From: Trish Cayetano @ 2015-07-18  9:00 UTC (permalink / 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-07-18 12:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-18  9:00 How to check if letters are in a string? Trish Cayetano
2015-07-18 10:23 ` 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

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