split data

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

I'm new to the C# world and learning as I go.
I have a question, I'm getting data back from my database such as

name/region.

How can I split this and only return the region?
 
I'm new to the C# world and learning as I go.
I have a question, I'm getting data back from my database such as

name/region.

How can I split this and only return the region?
If it is a string I.e. "John Doe/New York" you can use
string[] splitString = nameRegion.Split('/');

then you can access name using splitString[0] and [1] for the region.
 
heres what i have and its not working, i'm a missing something or is the
syntax incorrect?

String User = request.Servervariables["AUTH_USER"];
string[] splitString = User.Split('/');
lblUser.text = User[2];

2 should be the user name only



Mark mm said:
I'm new to the C# world and learning as I go.
I have a question, I'm getting data back from my database such as

name/region.

How can I split this and only return the region?
If it is a string I.e. "John Doe/New York" you can use
string[] splitString = nameRegion.Split('/');

then you can access name using splitString[0] and [1] for the region.
 
heres what i have and its not working, i'm a missing something or is the
syntax incorrect?

String User = request.Servervariables["AUTH_USER"];
string[] splitString = User.Split('/');
lblUser.text = User[2];

2 should be the user name only
Remember arrays are 0 indexed ie the second element will be 1.
If you put a break point at the lblUser.. statement and look at what
splitString contains it may reveal more.
 
its actually blowing up on this \ when i try to split the string
it should be

String User = request.Servervariables["AUTH_USER"];
string[] splitString = User.Split('\'); 'receiving error here when
compiling.
lblUser.text = User[2];

does C# not like the backslash? \



Mark mm said:
heres what i have and its not working, i'm a missing something or is the
syntax incorrect?

String User = request.Servervariables["AUTH_USER"];
string[] splitString = User.Split('/');
lblUser.text = User[2];

2 should be the user name only
Remember arrays are 0 indexed ie the second element will be 1.
If you put a break point at the lblUser.. statement and look at what
splitString contains it may reveal more.
 
i got it working now


Mike said:
its actually blowing up on this \ when i try to split the string
it should be

String User = request.Servervariables["AUTH_USER"];
string[] splitString = User.Split('\'); 'receiving error here when
compiling.
lblUser.text = User[2];

does C# not like the backslash? \



Mark mm said:
heres what i have and its not working, i'm a missing something or is the
syntax incorrect?

String User = request.Servervariables["AUTH_USER"];
string[] splitString = User.Split('/');
lblUser.text = User[2];

2 should be the user name only
Remember arrays are 0 indexed ie the second element will be 1.
If you put a break point at the lblUser.. statement and look at what
splitString contains it may reveal more.
 
Back
Top