Solved

Using indexOf to get userid from login credentials

Posted on 2010-08-18
3
327 Views
Last Modified: 2013-12-17
I need to use c# to pull the userid from the user's login credentials.  I keep getting an error that says "[System.ArgumentOutOfRangeException] = {"Index and length must refer to a location within the string.\r\nParameter name: length"}"
string pmUser = "network\msmith";
int pos = pmUser.IndexOf("\\");
string userid = pmUser.Substring(pos + 1, pmUser.Length - pos)

Open in new window

0
Comment
Question by:jmpatton
  • 2
3 Comments
 
LVL 27

Accepted Solution

by:
nmarun earned 500 total points
ID: 33467560
Here's a simpler version of what you're trying to achieve.string userid = pmUser.Substring(pmUser.IndexOf(@"\")+1);Arun
0
 
LVL 27

Expert Comment

by:nmarun
ID: 33467569
Plus you need an escape character '@' for the first line as well:string pmUser = @"network\msmith";Arun
0
 

Author Closing Comment

by:jmpatton
ID: 33467605
Thanks for the quick reply
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question