Extract right part of a string 
Author Message
 Extract right part of a string

Hi,
I'm programming an Outlook contactform and have the following problem:
I have a field where a full name is in. The Firstname is always the same length,
4 characters.

e.g.:
Paul Miller
Paul Ravenclaw
Paul Smith
Paul Graveyard
Paul Hill
etc.

Now I need to cut off the first 5 characters from this field (Paul + " ") with
VBScript in the form, so that I can use the last name in other fields. I've
tried it with the REPLACE funtion but I couldn't get it to work. The problem is
the differnt length of the lastname.

BTW: There is no other way to access the "lastname", because in reality it isn't
the name field, it's something different, I just took the name field for
explanation purposes ;-)

Can someone please give me a hint how to solve this problem with VBScript or
with formulas in Outlook fields?

Thank you!!!

Florian



Mon, 16 May 2005 22:21:07 GMT  
 Extract right part of a string
You could split it on the space: split(name, " ")(1) <- takes the second
part after the split.

You could use RIGHT and INSTR: Right(name, Len(name)-Instr(name, " ")) Or
Right(name, InstrRev(name, " "))

You could use MID: MID(name, Instr(name, " "))


Quote:
> Hi,
> I'm programming an Outlook contactform and have the following problem:
> I have a field where a full name is in. The Firstname is always the same
length,
> 4 characters.

> e.g.:
> Paul Miller
> Paul Ravenclaw
> Paul Smith
> Paul Graveyard
> Paul Hill
> etc.

> Now I need to cut off the first 5 characters from this field (Paul + " ")
with
> VBScript in the form, so that I can use the last name in other fields.
I've
> tried it with the REPLACE funtion but I couldn't get it to work. The
problem is
> the differnt length of the lastname.

> BTW: There is no other way to access the "lastname", because in reality it
isn't
> the name field, it's something different, I just took the name field for
> explanation purposes ;-)

> Can someone please give me a hint how to solve this problem with VBScript
or
> with formulas in Outlook fields?

> Thank you!!!

> Florian



Mon, 16 May 2005 23:21:31 GMT  
 Extract right part of a string

Quote:

> I'm programming an Outlook contactform and have the following problem:
> I have a field where a full name is in. The Firstname is always the same length,
> 4 characters.

> e.g.:
> Paul Miller
> Paul Ravenclaw
> Paul Smith
> etc.

> Now I need to cut off the first 5 characters from this field (Paul + " ") with
> VBScript in the form, so that I can use the last name in other fields. I've
> tried it with the REPLACE funtion but I couldn't get it to work. The problem is
> the differnt length of the lastname.

Hi

Using Right and Len:

sName = "Paul Miller"

sLastPart = Right(sName, Len(sName) -5)

MsgBox sLastPart

--
torgeir
Microsoft MVP Scripting and WMI
Porsgrunn Norway



Mon, 16 May 2005 23:36:57 GMT  
 Extract right part of a string

: Hi,
: I'm programming an Outlook contactform and have the following problem:
: I have a field where a full name is in. The Firstname is always the same length,
: 4 characters.
:
: e.g.:
: Paul Miller
: Paul Ravenclaw
: Paul Smith
: Paul Graveyard
: Paul Hill
: etc.
:
: Now I need to cut off the first 5 characters from this field (Paul + " ") with
: VBScript in the form, so that I can use the last name in other fields. I've
: tried it with the REPLACE funtion but I couldn't get it to work. The problem is
: the differnt length of the lastname.
:
: BTW: There is no other way to access the "lastname", because in reality it isn't
: the name field, it's something different, I just took the name field for
: explanation purposes ;-)
:
: Can someone please give me a hint how to solve this problem with VBScript or
: with formulas in Outlook fields?
:
: Thank you!!!
:
: Florian

name = "Paul Miller"
LastName = mid(name,6)
msgbox lastName



Tue, 17 May 2005 07:13:16 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. extracting multiple parts of string

2. Extracting part of a string

3. Extracting Part of a String

4. String extract functions, left,right.mid don't work

5. best way to extract strings from semicolon delimited strings

6. Q (linux): How to extract parts from ps into ps/eps

7. Extracting part of a HUGE page!

8. Q: Wanna extract part of PS/EPS preserving vector info

9. extracting a part of PS file

10. How do I search a readline string & extract parts of the string to a file?

11. Reading NTFS Rights vía ASP Part 2

12. Extract Filename Parts

 

 
Powered by phpBB® Forum Software