Jump to content
Sign in to follow this  
datatek

StringInStr StringSplit

Recommended Posts

datatek

$voller_name = ($vorname & " " & $nachname)
$Name_conv = StringLower(StringReplace(StringReplace(StringReplace(StringReplace(StringReplace(StringReplace(StringReplace($voller_name,"ü","ue"),"ö","oe"),"ä","ae"),"ß","ss"),"Ü","Ue"),"Ö","Oe"),"Ä","Ae"))

If StringInStr($Name_split[$Name_split[0]], '-') Then
    $var = StringSplit($Name_split[$Name_split[0]], '-')
    $Name_split[$Name_split[0]] = $var[$var[0]]
EndIf
$bname = StringLeft($Name_split[1], 1) & "." & $Name_split[$Name_split[0]]

In the above code first name and surname are split and, if there is a hypen in the name, the second part selected for $bname.

I need to have the first part before the hypen, instead of the second.

Could someone help?

Share this post


Link to post
Share on other sites
dbzfanatic

Would you mind giving an example output? Your code seems a bit...messy. What exactly are you trying to do by the way? There may be an easier way to do it.

Share this post


Link to post
Share on other sites
datatek

Would you mind giving an example output? Your code seems a bit...messy. What exactly are you trying to do by the way? There may be an easier way to do it.

If I put in the name "Sam Adams", the output is s.adams (this is also what I want).

If I put in the name "John Smith-Weston", the output is j.weston, but I want j.smith (the part before the -, not the part after it).

The relevant part of the code is

If StringInStr($Name_split[$Name_split[0]], '-') Then
    $var = StringSplit($Name_split[$Name_split[0]], '-')
    $Name_split[$Name_split[0]] = $var[$var[0]]
EndIf

Share this post


Link to post
Share on other sites
dbzfanatic

Full working code. Short,simple, to the point

$name = InputBox("Name","Enter your name","")

If StringInStr($name,"-") Then
    $split = StringSplit($name,"-")
    $newname = StringSplit($split[1]," ")
    $out = StringLeft($newname[1],1) & "." & $newname[2]
EndIf

MsgBox(0,"",$out)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.