Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!
What is the best way to select the text (for example: an email address) up to a certain character? For example, if I only want the username of this email address "bobsacamono" which obviously goes to "@" what is the most efficient way or isolating my substring?
on mouseUp
put "bobsacamono@seinfeld.com" into tEmail
put offset ("@", tEmail) into tBreakpoint
put char 0 to tBreakpoint - 1 of tEmail into tEmail
answer tEmail
end mouseUp
Good suggestion, however, I started off using that but in my actual use-case I am parsing through a directory containing multiple emails using a loop so then I get junk items created as a result of breaking apart the string like that. In this case, item 2 is junk.
item 1 = bobsacamono
item 2 = @seinfeld.com
I guess I just need to figure out how to isolate only item 1 in my loop. I'll take another look and come back with my code.
Thanks!
on mouseUp
put field 1 into tData
set the itemDelimiter to "@"
repeat for each line anAddress in tData
put word - 1 of item 1 of anAddress & cr after tCollect
end repeat
delete last char of tCollect -- a return
put tCollect into field 2
end mouseUp
local emailArray
set the itemdel to "@"
put the keys of emailArray into tKeys
repeat with x = 1 to the number of lines in tKeys
put item 1 of emailArray[(line x of tKeys)] into emailArray[(line x of tKeys)]
end repeat
And there will be not ".com" 's floating around in cyber space causing bloat because the data is overwritten. To not overwrite, then change the second array's name to something slightly different (EX: emailArray2)
I like that solution as well, very elegant! I'm beginning to see that there is "more than one way to skin a cat" in LiveCode. I am always looking for the fastest and simplest solutions, which I think you all have given me.
Yet another way to find all usernames (as first part of of 'email-words') in any string:
for example in
"He, and also she, use office: joe@iMail.com / private: alice@youMail.com"
function userNames S
set linedelimiter to "@"
repeat for each line L in S
put cr & last word of L after T
end repeat
delete char 1 of T; return T
end userNames