Solved

Using indexOf to get userid from login credentials

Posted on 2010-08-18
3
320 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 your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now