Thanks!
On Feb 23, 11:58 pm, Theraot <[email protected]> wrote: > Hello, > > Now I have to say don't cry >-<, no, don't care. I have to apologize > too, as I didn't undestand that the problem was that initialization, I > just did what you asked. That is telling what the function does... > > Anyway, I may have also took you to formal > documentation:http://msdn.microsoft.com/en-us/library/aa288453(VS.71).aspxunder > Initializing Arrays (aprox half way of the document). And this one for > character > literals:http://msdn.microsoft.com/en-us/library/aa691087(VS.71).aspx > > Now all is good again ^_^ > > Al J. Ramos > > On 23 feb, 08:23, Learner <[email protected]> wrote: > > > > > THANK YOU to all of you for taking time to explain my question. I > > was not clear about the new char[]{'\\'} and it makes sense now. > > > Ramos - First off sorry for not using the word PLEASE. I would use a > > lot of these before in the beginning but what I understand from the > > forums online is that asking a question clearly is more/equally > > important. But I should have said PLEASE and I apologize for not using > > it. > > > On Feb 23, 12:00 am, Theraot <[email protected]> wrote: > > > > Hello, > > > > To answer you, the function takes an string and returns what it says > > > after its last "\". > > > > It can be replaced with this equivalent potentially-more-clear less- > > > memory-expensive code: > > > > public static string ExtractUserName(string path) > > > { > > > //Adding 1 to avoid returning the "\" and also to avoid an > > > exception if the string doesn't contain any "\". > > > return path.Substring(path.LastIndexOf('\\') + 1); > > > } > > > > Take care of not passing null, on either version, because it will > > > throw an exception in that situation. > > > > I recomend to add the following code at the begin of the method unless > > > you want / expect the exception I mentioned above: > > > if (String.IsNullOrEmpty(path)) > > > { > > > return String.Empty; > > > } > > > Another option is to surround the code with a try, which in .NET > > > generated a faster code, as try is inexpensive in .NET (this is not > > > true in others platforms such as Java), but programming for the > > > exception is usually harder to undestand. > > > > Also make '\\' a constant. > > > > And for such weird* question, can you please add a please next time? > > > thanks. > > > *Why this question is weird: because it makes me feel like if I were > > > on an exam, and not like I were helping or solving a problem. Perhaps > > > more context would help too. > > > > PD: can anybody tell me how a path comes to give an user name? which > > > is what I can tell from the naming of the method. > > > > Cheers! > > > Al J. Ramos > > > > On 22 feb, 11:01, Learner <[email protected]> wrote: > > > > > Hi, > > > > > Can some one explain the below function > > > > > public static string ExtractUserName(string path) > > > > { > > > > string[] userPath = path.Split(new char[] { '\\' }); > > > > return userPath[userPath.Length - 1]; > > > > } > > > > > Thanks, > > > > > L- Hide quoted text - > > - Show quoted text -
