Question:
Delphi Problem - String?
2007-10-17 10:03:16 UTC
In my program, I would like the program to check if the string is equal to, for example, hello and then whatever they have entered. For example, they have to enter 'hello steve' and, using an if statement, to check if the text box contained 'hello ' and then steve is optional. steve could be anything.

using if edit1.text = 'hello' wont work as they would of inputed 'hello bob'

Does anyone have a solution to my problem?
Thanks in advanced
Three answers:
Neil P
2007-10-20 04:23:04 UTC
if copy(edit1.text,1,5) = 'hello'

-- does the first characters of edit1.text = 'hello'



Here is a utility function I have written:



function StartsWith(const StringToCheck, TestString : String) : Boolean;

begin

Result := (copy(StringToCheck, 1, length(TestString) ) = TestString);

end;



So you could write

if StartsWith(edit1.text,'hello') then



Have a look at 'String handling routines' in the help for more, particularly 'Pos', 'SameText', 'Trim', 'UpperCase', 'LowerCase'



Good luck

Neil
Haley
2007-10-17 12:04:36 UTC
Is Delphi a language? If it is, I am unfamiliar with it. Anyway, I would try looking for functions like split() or token tokenize strtkn. In other languages, you can give functions like these a character to look for, like a space, and it will return you the location in the string that character next appears or an array with the string split up according to that character. Hope that can help.
sievert
2017-01-04 00:41:07 UTC
in case you double click on the kind and bypass to the varieties OnCreate adventure. interior of that proceedure you initialize the Message1 variable with 'hi, my call is: ' like this Message1 := 'hi, my call is: ' ; then you initialize the Message2 variable with 'I stay interior the ' like this Message2 := 'I stay interior the ' ; You initialize MyName variable with 'Your call' like this MyName := 'Mary Jane' ; You inialize MyStreet with 'Your street' like this MyStreet := 'considerable street' This instruments each and every thing up whilst the kind is created so which you would be able to set off the activities at the back of the buttons or different activities. The OnCreate adventure happens first so all your variables are initialized till now the different calls can take place by this device. Then interior the OnClick adventure for Button one million your basically concatenating the variables at the same time to make a line to be displayed in a sort label. you do no longer point out it, yet you were not in any respect requested to additionally place a label merchandise on the kind? you will of direction choose one to exhibit your message from the button one million click adventure. I additionally assume that button 2 is under no circumstances used interior the lesson. can not help with the ambiguous blunders message. as long as you declared the variables interior the regular public Declarations area of the kind unit you may desire to be advantageous. make effective your syntax punctuation is actual. I continually omit a bracket or that darned semi-colon to debris me up.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...