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 [
Mike MillerSoftware EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jeff CertainCommented:
If fullName.IndexOf("[")>0 then
    fullName = fullName.Substring(fullname.indexof("["))
end if
Fernando SotoRetiredCommented:
Try this

        Dim SplitName() As String

        SplitName = fileName.Split("["c)

SplitName(0) will always have the fileName even if it does not have a "[" character in the name

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Fernando SotoRetiredCommented:
It should work this way as well

Dim fullName() As String

fullName = result.Properties("displayName")(0).Split("["c)
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

Mike MillerSoftware EngineerAuthor Commented:
Cast from type 'String()' to type 'String' is not valid.


on all of them
Mike MillerSoftware EngineerAuthor Commented:
nevermind...i see what i did
Mike MillerSoftware EngineerAuthor Commented:
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,
Jeff CertainCommented:
fullName = result.Properties("displayName")(0).Split(" [")
Mike MillerSoftware EngineerAuthor Commented:
tried that and got...
Character constant must contain exactly one character.
Jeff CertainCommented:
Alright then... I'll stand by my original suggestion:

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

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

[whatever]
instead of
LastName, FirstName

??
Jeff CertainCommented:
sorry... forgot it was start,length... not just length...

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

        Dim SplitName() As String

        SplitName = fullName.Split(" "c)


Fernando SotoRetiredCommented:
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
       
Mike MillerSoftware EngineerAuthor Commented:
Thanks guys...it's all working great now! :-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.