Using indexOf to get userid from login credentials

Posted on 2010-08-18
Medium Priority
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

Question by:jmpatton
  • 2
LVL 27

Accepted Solution

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

Expert Comment

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

Author Closing Comment

ID: 33467605
Thanks for the quick reply

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Hi, this video explains a free download that you can incorporate into your Access databases, or use stand-alone for contact management. Contacts -- Names, Addresses, Phone Numbers, eMail Addresses, Websites, Lists, Projects, Notes, Attachments…
Through the video, you can check the migration process of Outlook PST file to PDF. Kernel for Outlook to PDF tool can convert Outlook emails with all attributes like Subject, To, From, Cc, Bcc and other folders such as Inbox, Outbox, Sent Items, Jun…

624 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