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

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.
System.Collections.Generic.List myList = new System.Collections.Generic.List(100); .NET Framework
System.Collections.Generic.List myList = new System.Collections.Generic.List (100); .NET Framework , myList, = , new, System.Collections.Generic.List<int> (100);" / > System.Collections.Generic.List<int> myList = new System.Collections.Generic.List<int> (100); Does this preallocate 100 integers? Also
System.Collections.Generic.List myList = new System.Collections.Generic.List(100); .NET Framework
System.Collections.Generic.List myList = new System.Collections.Generic.List (100); .NET Framework , myList, = , new, System.Collections.Generic.List<int> (100);" / > System.Collections.Generic.List<int> myList = new System.Collections.Generic.List<int> (100); Does this preallocate 100 integers? Also
System.Collections.Generic.List myList = new System.Collections.Generic.List(100); .NET Framework
System.Collections.Generic.List myList = new System.Collections.Generic.List (100); .NET Framework , myList, = , new, System.Collections.Generic.List<int> (100);" / > System.Collections.Generic.List<int> myList = new System.Collections.Generic.List<int> (100); Does this preallocate 100 integers? Also
Generic.List .NET Framework
Hello, I have an Enum and a Generic.List(Of Enum) 1 Public Enum Mode 2 Count 3 Day 4 Month 5 End Enum Can my Generic List have duplicated values? For example: 1 Dim gl As Generic.List(Of Mode) 2 gl.Add(Mode.Count) 3 gl.Add(Mode.Count) I suppose Mode
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
Dispose Generic List .NET Framework
I have filled generic list with data on one form. When I close form generic list stay in memory waiting GC to collect. I want to implement code on form close to dispose generic list. C# Discussions Form.Close (1) ShowDialog (1) Dispose (1) Collect (1) GC (1) Mariani (1
difference between Generic.List and List .NET Framework
Is there any difference between Generic.List(Of MyClass) and List(Of MyClass)? VB.NET Discussions MyClass (1) Rowe (1) Seth (1) Namespaces (1) You might namespaces" and find this one out for yourself. . . . Thanks, Seth Rowe [MVP] keywords: difference, between, Generic.List, and, List description: Is there any difference between Generic.List(Of MyClass) and List(Of
Property. Which one should I use? .NET Framework
difference between defining a control property in the following two ways: ' Items . . . Private _Items As Generic.List(Of ListItem) = New Generic.List(Of ListItem) * ** * Property Items() As Generic.List(Of ListItem) Get Return _Items End Get Set(ByVal value As Generic.List(Of ListItem)) _Items = value End Set End Property ' Items Or ' Items . . . Private _Items As Generic
Generic.List. Is this possible? .NET Framework
Hello, I have a Generic.List of a structure that has 3 variables: name, value, amount How can I alphabetically order the items in the generic list by using the name variable? Thanks, Miguel ASP.NET Discussions IComparable (1) Sort (1) Miguel 1) Make the structure implement IComparable<T> then call list.Sort(); HTH, Sam - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - We're hiring! B-Line Medical is seeking .NET Developers for exciting technologies in a relaxed team environment. See ads on Dice.com. What framework version? keywords: Generic.List., Is, this, possible? description: Hello, I have a Generic.List of a structure that
Generic.List .NET Framework
Hello, I have a Generic.List(Of MyClass) MyClass has two properties: ID and Value, both strings. I want to look for the item, in my Generic.List(Of MyClass), with a given ID. How can I do this? Thanks, Miguel ASP.NET 1) Visual (1) MyClass (1) Switzerland (1) Andersson (1) ThereIts (1) By looping through the list and looking for the id. If you would use a Dictionary<sring, MyClass> instead, and www.guffa.com Hello there Its also possible to implement a class that derives from List<MyClass> and implement a ContainsKey method. In this method, you can use the Enumerator to