Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Using indexOf to get userid from login credentials

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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

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…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

824 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