Silverlight / WPF - Add next line(\n) in a generic List contains more than 100 characters

Asked By gopal krish on 28-Jun-12 04:45 AM
Earn up to 10 extra points for answering this tough question.
hi..

i have a generic list contains 100 index values..

for examples

private List<string> _list=new List<string> ();

 _list.Add("The Microsoft Developer Network (MSDN) is the portion of Microsoft responsible for managing the firm's relationship with developers and testers, such as: hardware developers interested in the operating system (OS), and software developers standing on the various OS platforms or using the API and/or scripting languages of Microsoft's applications. The relationship management is situated in assorted media: web sites, newsletters, developer conferences, trade media, blogs and DVD distribution. The life cycle of the relationships ranges from legacy support through evangelizing potential offerings.");

            _list.Add("welcome");

here i need to give "\n" if the index contains more than 100 characters.


i have used the below lines 

 static IEnumerable<string> Split(string str, int chunkSize)
        {
            return Enumerable.Range(0, str.Length / chunkSize)
                .Select(i => str.Substring(i * chunkSize, chunkSize));
        } 


  IEnumerable<string> ss = Split(_list[0].ToString(), 100);  
in the above line i need to pass my whole list values and split if any index contains more than 100 characters.
but i passed the static index value of my list. but i need to pass my whole list.

i dont waant to use for loop. is it possible to achieve this in linq..

need ur suggestions with examples...

regards
gopal.s



Jitendra Faye replied to gopal krish on 29-Jun-12 12:31 AM
Use this working code-


       List<string> _list=new List<string> ();
       _list.Add("a");
       _list.Add("asjgjkfsdhgjkfhsdjkghjkfsdgjkhfksdgkjfjksdgkfsdgkhfsdkggggggggggggggggggggggggggggggggggggggggggggggggggggggggghsdfgjkfsdjkgjkjkjkjkjkjkjkjkjkjkjkjkjkjkjkjk");
       _list.Add("b");


       foreach (string str in _list)
       {
         if (str.Length > 100)
         {
           string s = str.Insert(100, "\n");
         }

       }

Try this and let me know.
       
help
I have a generic list. Where I have to get for each customer there can be more than one Address List<CustomerViewer.localhost.Customer> list = new List<CustomerViewer.localhost.Customer> (objGetCustomers.GetAllCustomers()); This list contains to classes one for customer
List<string> list = new List<string> (); when i insert integer inthis it shows error then how come this is generic list<object> = new list<object> (); this is generic ? when we specify the datatype how is it generic HI Generics provide type safety without the overhead of multiple implementations. Ex. We can create
Hi, I want to know the usage of generic list in asp.net. How to use this in asp.net application. Can you give me compile time error. • In another sense, if we have string and int in a same list then it will throw a compile time error. • Generics are available System.Collections.Generic Namespace. • Generics introduce to the .NET Framework the concept of type parameters, which make it val) { } } / / Create another class which consume MyGeneric class class MyGenericTest { static void Main() { / / Declare a generic list of type int MyGeneric myGenericObj1 = new MyGeneric (); / / Declare a generic list of type string MyGeneric
I have a generic list of a class that I created. . . Dim eventlst As New List ( Of CMSEvent ) This list is databound to a gridview. I need to be able to sort based on the you might get an idea http: / / stackoverflow.com / questions / 438715 / how-sort-a-system-collections-generic-list-in-vb-net http: / / weblogs.asp.net / kiyoshi / archive / 2009 / 02 / 17 / render-aspx
I use Generic List containg productid productname ProdPrice I want to remove item from the list whose productid = 10 Here is general logic to do it / * suppose this is your list * / List < prod > lst = new List < prod > (); for ( int i = 0; i < lst.Count; i++) { if (lst[i].id = = 10) { lst
of wildcard filters." / > Illustrates the use of a Predicate to enable the Generic List FindAll method to create a sub List<> of wildcard filters. The Generic List class is a lot more useful than its pre- .NET 2.0 brethren such as the Hashtable. The List class offers a number of "Find" type builtin methods. In order to enable a specific
I have a generic list which contains a class called Parameter. Parameter contains 2 integers, ParamType and ParamValue. A generic list is built containing a small number of values List<Parameter> myList I have created a function which passes in 2 parameters. These are passed that doesn't have a reference pointer to an item that actually exists in your list. Yes Robbe is spot on. You are storing a different instance and while removing you
Hi, Can anybody explain me how to sort generic list Thanks. you can do it like below code List < string > lst1 = new List < string > (); lst1.Add( "zxy" ); lst1.Add( "abc" ); lst1.Add( "123" ); lst1.Add( "rtc" ); lst1.Sort keywords: Sort, new List, Sorting description: Sorting Generic List Hi, Can anybody explain me how to sort generic list Thanks. 06-Jun-13
Hi All, I need an urgent help. How can we check duplicates in a Generic List ? This list contains a class object, which have values ID & Name. I want to check whether some protected void Page_Load( object sender, EventArgs e) { string [] input = { "Amit" , "Sumit" , "Ravi" , "Amit" , "Sumit" , "Ajit" }; List< string > list = new List< string > (input); List< string > result = removeDuplicates(list); } static List< string > removeDuplicates(List< string > inputList) { Dictionary
Hi, I need to convert / cast a generic list containing TaskItems to an Outlook .Items list. i tried this but it doesn't work: List< TaskItem > lst = new List< TaskItem > (); lst.Add( myTaskItem ); Outlook. Items outItems = (Outlook. Items )lst; Can anyone please show me