Jump to content

StringInStr StringSplit


datatek
 Share

Recommended Posts

$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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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)
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...