Link to home
Start Free TrialLog in
Avatar of Member_2_1242703
Member_2_1242703

asked on

help with a string

fullName = result.Properties("displayName")(0)


How would I say...
if fullName includes a [ then chop off everything to the right of [
Avatar of Jeff Certain
Jeff Certain
Flag of United States of America image

If fullName.IndexOf("[")>0 then
    fullName = fullName.Substring(fullname.indexof("["))
end if
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It should work this way as well

Dim fullName() As String

fullName = result.Properties("displayName")(0).Split("["c)
Avatar of Member_2_1242703
Member_2_1242703

ASKER

Cast from type 'String()' to type 'String' is not valid.


on all of them
nevermind...i see what i did
is there a way to split everything after a space and then [

if the string was LastName, FirstName [whatever]
then i would want my value to be
LastName, FirstName

i tried
fullName = result.Properties("displayName")(0).Split(" ", "["c)
but it returns
LastName,
fullName = result.Properties("displayName")(0).Split(" [")
tried that and got...
Character constant must contain exactly one character.
Alright then... I'll stand by my original suggestion:

 If fullName.IndexOf("[")>0 then
    fullName = fullName.Substring(fullname.indexof(" ["))
end if
oops

If fullName.IndexOf(" [")>0 then
    fullName = fullName.Substring(fullname.indexof(" ["))
end if
wouldn't that return everything to the right of the [

[whatever]
instead of
LastName, FirstName

??
sorry... forgot it was start,length... not just length...

If fullName.IndexOf(" [")>0 then
    fullName = fullName.Substring(0,fullname.indexof(" ["))
end if
Sorry I was away from my desk.

        Dim SplitName() As String

        SplitName = fullName.Split(" "c)


Sorry I was away from my desk.

Imports System.Text.RegularExpressions

        Dim SplitName() As String

        SplitName = fullName.Split(" "c)
        SplitName(0) has the first part of the name just before the space
        SplitName(1) Has everything after the space

I am using Regular Expressions to remove the { } if any

        Dim m As Match = Regex.Match(SplitName(1), "\[(?<LName>.*)\]|(?<LName>.*)")
        SplitName(1) = m.Groups("LName").Value

Sorry about the delay, fires to put out
       
Thanks guys...it's all working great now! :-)