vb.net Code:
Function CreateUserName(givenName As String, surname As String) As String
Dim substringLength = 1
Dim userName As String
Do
userName = givenName.Substring(0, substringLength) & surname
substringLength += 1
Loop Until IsUniqueUserName(userName)
Return userName
End Function
That handles what you've asked for but it will crash if it gets to the end of the given name without finding a unique user name. You haven't told us what you want to do in that case so I haven't included it. Hopefully it's obvious that you need to implement the IsUniqueUserName method yourself.