Delphi Help!

acidrain

Executive Member
Joined
Jan 7, 2007
Messages
6,966
Reaction score
1,765
Location
At a computer
Hi guys,

Im busy working on an assignment using delphi where the question wants us to modify and transfer a string into a listbox.

The string must first be modified in the following way:
Blanks must be trimmed before and after the string
All vowels ( upper and lower case ) must be removed.

Only then will the word be transfered to the list box.

Can anyone help me with the command as the book seems to be unclear about it and ive spent hours now searching the web with no luck.

Thanks
 
Its been a while since ive done some delphi...

Dunno how right this is or if it will even help..(Dont have delphi installed either to test it out)

But considering nobody else has responded, and considering i felt like giving it a shot, here it goes:

-----------------------------------------------------------------------------------------------------------------------------------

stringOld=textbox1.text

for i = 1 to length(string1) do
begin
if stringOld <> " " then
stringNoSpaces=stringNoSpaces + stringOld
end

if NOT stringNoSpaces IN ['A','E','I','O','U'] then
stringNew=stringNew + stringNoSpaces
end

(guess you could put this in the first IF statement with the use of an AND but what the heck...thought it better explains each process like this...)

One IF statement:

for i = 1 to length(string1) do
begin
if (stringOld <> " " ) AND (NOT(stringOld IN ['A','E','I','O','U'])) then
stringNew=stringNew + stringOld
end

Also dont forget to initialize your string variables:
stringNew=""

;)

-----------------------------------------------------------------------------------------------------------------------------------

As i said, i dont program in Delphi anymore..Hope u get the general outline though

Good luck
 
Last edited:
Which commands are you looking for? the 1 to tell you a position of something? or how to delete the vowels (which as far as I know would just be a loop that checks each character and deletes it if its a vowel)
 
Which commands are you looking for? the 1 to tell you a position of something? or how to delete the vowels (which as far as I know would just be a loop that checks each character and deletes it if its a vowel)

Just to delete the vowels and spaces from a string given in the Edit Text box.
 
^^

Did i write all that for nothing.... :confused:

Not at all, busy trying it out now.

Does it definitely have to have a for loop? Basically asking if there is not one function that will check the entire string without having to check the characters one by one and modifying it.
 
Last edited:
stringOld := textbox1.text;

for i := 1 to length(stringold) do
begin
if ((stringOld) <> " ") and (not(upcase(stringold IN ['A','E','I','O','U']))) then
stringNew := stringnew + stringold;
end;

that should work I think, not to sure about the "not" part, and borrowed some of your code fxit :)
 
stringOld := textbox1.text;

for i := 1 to length(stringold) do
begin
if ((stringOld) <> " ") and (not(upcase(stringold IN ['A','E','I','O','U']))) then
stringNew := stringnew + stringold;
end;

that should work I think, not to sure about the "not" part, and borrowed some of your code fxit :)


lol i totally forgot bout the upcase part...

Also not sure bout the NOT part :p And the + bit ^^ :( Told u im rusty :p
No worries man..as long as this dude gets the help he needs :)
 
stringOld := textbox1.text;

for i := 1 to length(stringold) do
begin
if ((stringOld) <> " ") and (not(upcase(stringold IN ['A','E','I','O','U']))) then
stringNew := stringnew + stringold;
end;

that should work I think, not to sure about the "not" part, and borrowed some of your code fxit :)


[Error] Illegal character in input file: "" ($22)
 
Ye i could get all the help i need since this violent flu ive got had left me bed-stricken for days so now i got 3hrs 10min to submit this assignment.

Brain also not working very well.
 
[Error] Illegal character in input file: "" ($22)

Weird!?

Aah its cos of the double quotation marks... Visual Basic is double hence the confusion.. But u should know that its single :p

Hmm...You said:

All vowels ( upper and lower case ) must be removed

@S1ght
So wouldnt we have to make all vowels Upper Case first? And then remove them then? Otherwise we would have to check twice? (Once for lower case vowels and once for uppercase vowels)

Dont worry man we'll get u through it :)
 
Last edited:
The assignment is to remove trailing and leading spaces, not all spaces. Should compile as is, but I haven't tried it:

Function AcidHomework(InputS:string):OutputS;
var
i:integer;
TempS:string;
Found:boolean;
begin

//Remove leading spaces and remove vowels
Found:=false;
If length(StringA)>0 then
For i:=1 to length(InputS) do
begin
If InputS<>' ' then Found:=true;
If Found then
if (Upcase(InputS) in ['A','E','I','O','U']) then
TempS:=TempS+InputS;
end;

InputS:=TempS;
//Remove trailing spaces
Found:=false;
If length(StringA)>0 then
For i:=length(InputS) downto 1 do
begin
If InputS<>' ' then Found:=true;
If Found then TempS:=TempS+InputS;
end;

OuputS:=TempS;
end;
 
okay thanks all...

all spaces are removed and vowels (lower case only), but now all thats left is to take out UpperCase vowels

UPDATE: lowercase and uppercase are removed as well as the spaces:
code:

word := edtWord.Text;
for i := 1 to Length(word) do
begin
if ((word) <> ' ') and (word IN ['a','e','i','o','u'])
and (word IN ['A','E','I','O','U']) then
NewWord := NewWord + word;
 
Last edited:
okay thanks all...

all spaces are removed and vowels (lower case only), but now all thats left is to take out UpperCase vowels

Havoc and s1ght are gonna show me up again :p

But whatever..What i would do is:

Before all of that code:

--------------------------------------------------------------------------

stringOld=UpperCase(StringOld)

That makes everything uppercase... So you wont have to check for lowercase as well :)

And then the rest of the code follows:

for i = 1 to length(string1) do
begin
if (stringOld <> " " ) AND (NOT(stringOld IN ['A','E','I','O','U'])) then
stringNew=stringNew + stringOld
end

--------------------------------------------------------------------------
 
Wouldn't assigning the string to all uppercase affect it when it gets transfered onto the listbox?

eg: i type bath... program puts it all in uppercase to test for vowels and then the output is BTH?

or wou;ld it not affect the output.

Also can you explain the 'IN' part. I can pretty much read it all and understand, but just want to know what the "IN" means
 
Ya that would prob work fxit but then his whole sentence would be in caps when it is displayed which is prob not what he wants :)

if (Upcase(InputS) in ['A','E','I','O','U']) then


Doesn't Havocs code already do the caps though?
 
Ya that would prob work fxit but then his whole sentence would be in caps when it is displayed which is prob not what he wants :)



Doesn't Havocs code already do the caps though?

Yeah kinda figured :D lol...

Forget about that line of code then... Just look at havocs code..

So then it would be something like this:

if (Upcase(StringOld) in ['A','E','I','O','U']) then
StringNew=StringNew + StringOld
 
Last edited:
Top
Sign up to the MyBroadband newsletter
X