Accessing elements of an array

  • Thread starter Thread starter Krish
  • Start date Start date
K

Krish

The following call returns something like US/ABCDEF

System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString()

I would like to split the string by "/" and access the 2 member OR
index of
1 in the array.


I tried doing something like

System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString().Split("/")[1];

Why does this not work
 
Try this

string IdName =
System.Security.Principal.WindowsIdentity.GetCurrent().Name;

int MaxReturnArrayCount = 2; //if you predict more increase this value.
char [] arr = new char[1];
arr[0] = '/';

//receive as string array
string [] splitedString= IdName.Split(arr,MaxReturnArrayCount );

Shak
 
Krish said:
The following call returns something like US/ABCDEF

System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString()

I would like to split the string by "/" and access the 2 member OR
index of
1 in the array.


I tried doing something like

System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString().Split("/")[1];

Why does this not work

String.Split() takes an array of characters, not a string.

Also, I suspect that the separator character in your identity string is
really a backslash ('\').

Try:

WindowsIdentity.GetCurrent().Name.ToString().Split( '\\')[1]
 
Back
Top