Question

I'm sure if I knew the correct terminology I may have been able to search an answer... But my Visual Studio VB skills are somewhat n00bish.

My VB runs a dos batch, that dumps the DOMAIN\USERNAME of the current logged on user for a given IP address to a text file (GETUSER.txt)

What I need to do with this string (taken from the txt file created above), is create two strings, one that is the DOMAIN, one that is the USERNAME and to drop the \ entirely.

The problem is that my work environment consists of multiple domains, and varying username styles. The only constant is the \ separating the DOMAIN and USERNAME.

I've looked at the REPLACE and various STRING functions, but I'm struggling folks.

The below is the section of VB code that runs when you click OK on the dialogue box (after entering an IP). "MAIN" is the name of the parent window that has the Public VARs in it.

Public Shared IPADDRESS As String
Public Shared USERNAME As String

^ are the Public VARS used.

    Dim GETUSER As New ProcessStartInfo("TOOLS\GETUSER.bat")
    Dim fileReader As System.IO.StreamReader
    Dim stringReader As String

    MAIN.IPADDRESS = NEW_IP_ADD.Text
    MAIN.IP_DISPLAY.Text = MAIN.IPADDRESS

    GETUSER.WindowStyle = ProcessWindowStyle.Hidden
    GETUSER.Arguments = MAIN.IPADDRESS
    Process.Start(GETUSER)

    fileReader =
    My.Computer.FileSystem.OpenTextFileReader("TOOLS\GETUSER.txt")

    stringReader = fileReader.ReadLine()
    MAIN.USERNAME = stringReader

    MAIN.USER_NAME.Text = MAIN.USERNAME

I hope this makes sense, and isn't too impossible to decipher... I look forward to your responses....

Please remember, I'm VERY new at VB, and Visual Studio... also... I'm more than happy if people post links to places that know I can get my answer, or help me with function names or anything designed to help me find the answer myself... it's the only way to learn... I just think I need a nudge in the right direction...

Cheers,

Tim.

Was it helpful?

Solution

It sounds like what you want to do is to split the string. And handily, there's a Split method:

Returns a string array that contains the substrings...

So you'd do something like:

Dim parts = MAIN.USERNAME.Split("\"C)
Dim domain = parts(0)
Dim userNameWithoutDOmain = parts(1)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top