Solved

Using indexOf to get userid from login credentials

Posted on 2010-08-18
3
330 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

627 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