?
Solved

how to find the first spca eon a srting (really eassy i just need urgent)

Posted on 2007-10-18
6
Medium Priority
?
142 Views
Last Modified: 2010-04-30
hi,
i have a string like this: Jhon Doe
how do i get to read that string and the until the space so in order words i need to get the part that display Jhon how do i do this?

i dont need a fix lenght of string because i have different records and all of them varies.
Thanks,
jsctechy
0
Comment
Question by:jsctechy
6 Comments
 
LVL 8

Expert Comment

by:Mikkk
ID: 20101485
name=split("Jhon Doe"," ")(0)
surname=split("Jhon Doe"," ")(1)
0
 
LVL 35

Expert Comment

by:mvidas
ID: 20101510
Hi jsctechy,

You can also use InStr() to determine the position of the first space, then use Left() to extract what comes before it:

 Dim oldStr As String, newStr As String, i As Long
 oldStr = "Jhon Doe"
 i = InStr(1, oldStr & " ", " ") 'append space after oldstr in case there is no space
 newStr = Left(oldStr, i - 1)

Matt
0
 
LVL 8

Expert Comment

by:Mikkk
ID: 20101513
Or you can do like this a (bit more complicated):

fullname="Jhon Doe"
name=left(fullname,instr(fullname," "))
surname=right(fullname,len(fullname)-instr(fullname," "))
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 20101555
Or you could just check the value returned from Instr() and act accordingly:

    Dim str As String
    Dim spcIndex As Integer
    Dim value As String
   
    str = "Jhon Doe"
    spcIndex = InStr(str, " ")
    If spcIndex > 0 Then
        value = Left(str, spcIndex - 1)
    Else
        value = str ' return the whole string since no space was found
    End If
    Debug.Print value
0
 
LVL 1

Author Comment

by:jsctechy
ID: 20101623
i need something simple get the string and output it to message box
thats all i need

string = Jhon doe

msgbox =>Jhon
thats all i need
0
 
LVL 8

Accepted Solution

by:
Mikkk earned 2000 total points
ID: 20101708
string1 = "Jhon doe"
msgbox(split(string1," ")(0))
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month15 days, 14 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question