Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

C# equivalent of C++ std::string find_first_not_of and find_last_not_of -


indexof, indexofany , lastindexof, lastindexofany dont seem these (or maybe do). i'm looking equialent of std::string's find_first_not_of , find_last_not_of. i'm thinking creating extension class i'm not sure if c# provides functionality.

string source = "the quick brown fox jumps on lazy dog"; string chars = "ogd hte";  int? firstnotof = source.select((x, i) => new { val = x, idx = (int?)i })                         .where(x => chars.indexof(x.val) == -1)                         .select(x => x.idx)                         .firstordefault();  int? lastnotof = source.select((x, i) => new { val = x, idx = (int?)i })                        .where(x => chars.indexof(x.val) == -1)                        .select(x => x.idx)                        .lastordefault(); 

or, if prefer non-linq extension methods. these should have better performance, findlastnotof:

int? firstnotof = source.findfirstnotof(chars); int? lastnotof = source.findlastnotof(chars);  // ...  public static int? findfirstnotof(this string source, string chars) {     if (source == null) throw new argumentnullexception("source");     if (chars == null) throw new argumentnullexception("chars");     if (source.length == 0) return null;     if (chars.length == 0) return 0;      (int = 0; < source.length; i++)     {         if (chars.indexof(source[i]) == -1) return i;     }     return null; }  public static int? findlastnotof(this string source, string chars) {     if (source == null) throw new argumentnullexception("source");     if (chars == null) throw new argumentnullexception("chars");     if (source.length == 0) return null;     if (chars.length == 0) return source.length - 1;      (int = source.length - 1; >= 0; i--)     {         if (chars.indexof(source[i]) == -1) return i;     }     return null; } 

(it's possible might better performance -- in both linq , non-linq versions -- if convert chars hashset<char>, or maybe plain char[] array. you'd need benchmark find out, though difference negligible unless chars gets pretty big.)


Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -