i have a username= LICTowner.
i need to get the prefix from the word LICTowner i.e LICT.
how to split the word and get the 4 letter prefix.
in asp.net using C#
i have a username= LICTowner.
i need to get the prefix from the word LICTowner i.e LICT.
how to split the word and get the 4 letter prefix.
in asp.net using C#
if the prefix is ALWAYS 4 letters you can use the Substring
method:
var prefix = username.Substring(0, 4);
where the first int is the start index and the second int is the length.
String userName = "LICTowner";
String prefix = userName.Substring(0,4); // LICT
String restOfWord = userName.Substring(4); // owner
hmmmm.... before anything, a) you should really look for similar questions and b) thats not a hard problem to do... i mean, have you even tried???
if the prefix is always 4 letters, then just use the .Substring method... as in
string username;
string prefix=username.Substring(0,4)// or something like that, cant remember off the top of my head
string s = "LICTowner";
Label1.Text= Regex.Replace(s, "[^A-Z]", "");
Simple regular expression to remove all characters other than upper case
If the prefix is always 4 characters use simple substring
Else a) remove all non upper case characters
string s = "LICTowner";
Label1.Text= Regex.Replace(s, "[^A-Z]", "");
b) split at the first non upper case character
Label1.Text= Regex.Split(s, "[^A-Z]")[0];
You can use the Substring() function to get the first four Character.
string mystring = "LISTowner"; string prefixword = mystring.Substring(0,4); Label label1 = new Label(); label1.Text = prefixword;