English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Hi im not sure what the command is I want to accomplish my task but here is what I am trying to do.

In my program i have a variable mystring = "yahoo mail - username" for example
i want to trim that variable down to just "username" and assign it to another variable
I thought trim is what i wanted but i think i was wrong.

Can someone help
Thanks

2007-04-13 18:46:52 · 3 answers · asked by julibabyca 1 in Computers & Internet Programming & Design

3 answers

There are a thousand ways to skin a cat......

Since you want to extract the username from an E-mail address try using the split command. Since all E-mails have a @ use the @ as the delimiter.

Edit:
You can use a dash as the dilimiter "-" or a string variable. So you can inclue the spaces on either side of the dash as the delimiter " - " (You would be interested in the ay(1) contents for the username).

The split command places the results in a string array

DIM ay() , usrName as string
usrName = "someName@yahoo.com"

ay = split(usrName,"@")

ay(0) will now contain "someName"
ay(1) will now contain "yahoo.com"

Reassign data from the array to usrName and do what ever you want to the usrName

usrName = ay(0)

2007-04-14 02:16:21 · answer #1 · answered by MarkG 7 · 0 0

Trim just removes spaces. But if in the string "yahoo mail-username" the dash '-' always appear, try getting a substring from mystring that starts from the position of the last or first dash till the end of the string. First or last dash doesn't matter here because you have onle one dash in the string. This will get you the username.

2007-04-14 01:57:37 · answer #2 · answered by haddadnasry 2 · 0 0

well, assuming your string will look exactly like that, this code should work

Dim mystring = "Yahoo Mail - username"
Dim result
result = mystring.ToString.Remove(mystring.ToString.IndexOf("Yahoo Mail -"));

although, its really not flexible enough ... I would need more information to help you further xD, Also, its proobbly not the best way of going about this function ... but it works :)

Im a c# programmer, not a vb programmer, its been a while since i last opened vb but I know that code will work.

Hope this helps!
-Bob

2007-04-14 01:57:02 · answer #3 · answered by Mr. Bob 3 · 0 0

fedest.com, questions and answers