.net - Convert StringCollection To List<String>

May 10, 2009

Normally, I'd choose List<String> [or, in VB, List(Of String)] over StringCollection whenever possible: see also Best string container.

However, as it seems, generics — and hence, List<String> — are apparently not supported in VS 2008's settings designer. Therefore, if I want to use a list of strings in my user settings, I have to resort to using a StringCollection there.

Now as I don't want to see StringCollection throughout my code, I need to convert it to List<String>. How do I do this efficiently? Or, even better, am I mistaken and there is a way to use List<String> in settings designer?

View 5 Replies


ADVERTISEMENT

Find A Substring In An ArrayList, StringCollection Or List(Of String)

Jun 7, 2010

I've got some code that creates a list of AD groups that the user is a member of, with the intention of saying 'if user is a member of GroupX then allow admin access, if not allow basic access'.

I was using a StringCollection to store this list of Groups, and intended to use the Contains method to test for membership of my admin group, but the problem is that this method only compares the full string - but my AD groups values are formatted as cn=GroupX, etc....

I want to be easily able to determine if a particular substring (i.e. 'GroupX') appears in the list of groups. I could always iterate through the groups check each for a substring representing my AD group name, but I'm more interested in finding out if there is a 'better' way.

Clearly there are a number of repositories for the list of Groups, and it appears that Generics (List(Of String)) are more commonly preferred (which I may well implement anyway) but there is no in-built means of checking for a substring using this method either.

I've settled on using a List(Of), and I've borrowed from Dan's code to iterate through the list.

View 3 Replies

Cast/convert From List(Of DataRow) To List(Of String)?

May 22, 2012

I'm trying to solve a problem regarding types of list. First of all I have a stored procedure in my DB which does a select of a single column and I try to proceed it in my app in VB. By making a method function I declared a DataTable that loads through the SqlCommand(with the CloseConnection behavior). After that I publicly declared a List(Of String) which needs to be populated with the rows/items from the stored procedure that is on the way. Below is my snippet of the code:

Dim dt As New DataTable()
Try
If conn.State = ConnectionState.Open Then

[Code]....

It's LPrefix = collection.Cast(Of String)() where I get an exception error telling me that I can't really convert it. The old fashion way is to iterate with for/for each loop but that's not what I want for best use of performance especially if the list will have thousands of rows from a single column. So basically, I want to insert those items from that DataTable to the List(Of String) without For/For Each loop.

Running on VisualStudio2010 Ultimate, .NET FrameWork 4.0.

View 2 Replies

Vb.net - Convert From Custom List To List Of String

Mar 25, 2010

I have the following code:

[code]...

The intention is to convert an IList of custom objects to a string equivalent comprising each element in the Ilist. Unfortunately I can't seem to find a way to get the underlying data of the custom object, and of course as in the above example, using object simply gives me a string of types definitions, rather than access to the underlying data.

View 2 Replies

Convert List Of String To A String Separated By A Delimiter

Apr 15, 2009

Whats the best way to convert a list(of string) to a string with the values seperated by ,

View 3 Replies

String.ToCharArray() Stored In StringCollection Conversion To Numbers And Back

Aug 25, 2009

I have a string which was converted to a char array and stored in a stringcollection, how do I return the numerical value for the character in each string? How can I reverse this process, getting the character from the numerical value?

I know I could code a Select Case statement, but that would take a very long time as I need to cover every character a person could want to conceivably use in the English language, including punctuation. Is there already a method built into vb.net for doing this?

View 2 Replies

How To Convert Csv String To List

Apr 8, 2011

[Code]...

How can I convert a csv string into a list in vb.net?

View 3 Replies

Convert List Of Directories To String?

Feb 10, 2010

I am trying to Add the name of every folder in a directory to a combobox as a string to use in other code. Then I would like to truncate the last 3 characters off of the folder names.Example:

My main directory is C:Main
My sub folders are C:MainsubOne_bp
C:MainsubTwo_bp
C:MainsubThree_bp

I want a combo box with the following added durring run time.

subOne
subTwo
subThree

The following code will get me the folder names in the combo box, BUT it will not truncate the _bp off of the end and they are added as IO.DirectoryInfo that cannot be used as a string in other tasks.

Dim dir As String = "C:Main"
If (System.IO.Directory.Exists(dir)) Then
Dim di_dir As New IO.DirectoryInfo(dir)

[code]....

View 3 Replies

Convert List Of String Into An Object?

Mar 6, 2012

I am looking for a way to convert my List(Of string) into an Object in vb. So in the end it would be the same as declaring Dim cArray() As Object = new Object. Can anyone point me to how i can achieve this? I cannot use the LINQ .ToArray as that creates a string array and this is not acceptable for my work. I need to pass this object into another one that has the parameter (aArray as Object).

View 4 Replies

Convert A List(of Long) Into A String Array?

Oct 26, 2009

I want to convert a List (of Long) into a string array.

Reason: it's a list of database IDs and I want to make a comma delimited string to pass into a stored proc.I tried this:

Dim commaDelimitedList As String = String.Join(",", itemIDList.Cast(Of String)().ToArray)

but I'm clearly not using the Cast correctly since it throws an exception:

System.InvalidCastException: Unable to cast object of type 'System.Int64' to type 'System.String'..

Is there a way to get Cast working for this, or am I stuck with ConvertAll and a delegate function?

View 3 Replies

Convert List(of T) Into Comma-separated String Of Id's?

Jan 27, 2012

I have a number of classes that all implement the same interface. e.g.

Public Class IncidentAsset
Implements IModelWithIdentity
Private _assetId As Int16
Private _otherAsset As String
Private _asset As Asset

[Code]...

Is there a better way of doing this in VB.NET using .NET 2.0?

View 1 Replies

Convert A List(of String) To String()?

Nov 11, 2011

Dim namelist As List(Of String) = New List(Of String)
namelist.Add("Hi")
namelist.Add("Hello")

[code].....

View 4 Replies

Convert A Textbox List To A Comma Separated String?

Mar 13, 2009

I have a text box with a list of entries for example:

Reference 1
Reference 2
Reference 3

[Code]....

I plan to read the string back into a the textbox later using the split() method and assign each to string to an array.

View 5 Replies

Convert Array List To Comma Separated String?

Aug 28, 2009

I'm using String.Join to attempt to turn an array list into a string that is comma separated, such as "1,2,3,4". I can't seem to get the syntax working.

Here's what I'm trying:

Dim aryTest As New ArrayList()
aryTest.Add("1")
aryTest.Add("2")
aryTest.Add("3")

[CODE]...

How can I go about doing this properly?

View 3 Replies

.net - Convert A List (Of KeyValuePair(Of String,Int32) Into A Dictionary(Of String, Int32) Using .ToDictionary?

Nov 2, 2010

To be able to sort a dictionary by value I'm using this code:

Dim idCurrentJobs As IDictionary(Of String, Int32) = New Dictionary(Of String, Int32)
'The string in the dictionary represents a jobname and the integer is a counter for how many jobs im currently are running in the application'
idCurrentJobs.Add("JobName1", 2)

[code]....

View 2 Replies

.net - Function To Accept List(Of String), Array & String And Similarly Return List(Of String)?

Jul 29, 2011

I want the Function to accept List(Of String), Array & String and similarly return List(Of String), Array & String respectively. The Function simply adds a string (month) to the input collection. I just want to use it for string, array and list with needing to think of conversions.

[Code]...

View 2 Replies

System.Collections.Specialized.StringCollection Vs System.Collections.Generic.List(Of?

Feb 5, 2011

[code]...

What's really the point in using the former?It's hard to use linq if I used the former. I have to convert that to an array first which is difficult because there is no (asarray) function.I think I would change all of my code that's using System.

Collections.Specialized.StringCollection to System.Collections.Generic.List(Of String)

View 2 Replies

Convert A Html String Or The Below Sting Into A Tree View Or A List View

Jun 9, 2009

the VB .net experts. I added the following code and I get an error as shown below.

[CODE]....

View 8 Replies

Convert A List Linq Expression To Defined List Class?

May 26, 2012

y have this class

Private Class MyClass
Public Property propertyOne() as String
Public Property propertyTwo() as String

[code].....

View 2 Replies

C# - With LINQ, How To Transfer A List<List<string>> To List<string>

Dec 15, 2010

I got an object of List<List<string>>I need to bring this into a ist<string>I have no idea how to do this with LINQ.

View 1 Replies

StringCollection Most Used Word ?

Mar 20, 2011

Does anyone knows how to get the most used word in a string collection. The second most used word etc. till the 10 most used words.

Example:
I have a string collection with.
Car
Car
Bike
Scooter
Car
Bike
Bike
Bike

Now i want to get the word Bike as first because this is the most used word. And after that i want the word Car because that is the second most used word. Then Scooter.

View 5 Replies

StringCollection : Check If It Has No Strings?

May 1, 2010

Here's a try on how to check if a sting collection has 0 strings[code]...

View 3 Replies

StringCollection In Application Settings?

Nov 11, 2005

tried using the application settings yet. Everything seems to work well except when I specify the type as a string collection. When I try to add new items at run time using the property window I get the following error:Constructor on type 'System.String' not found.Do I need to do something else to make this work?

View 4 Replies

StringCollection Or ArrayList Within Class?

Nov 10, 2009

I have a class called CookieMonster, its objective is to simply create a cookie based on 3 parameters passed to it. The cookie name, the cookie name-value pairs and the cookie expiry date.I have experimented with List(of T) and Array and StringCollection, but I'm unsure which is the best for passing the name-value pairs and providing that information to the class.Ideally, I'd like to be able to do something like this:

Dim l As New List(Of String)
l.Add("name", "value")
l.Add("name", "value")

[code].....

View 2 Replies

Get Text From Image Field Into StringCollection?

May 5, 2009

I am Delphi programmer and I am new in .net with VB code How to get text from sql server image field to StringCollection, in Delphi I use code:

[Code]...

View 4 Replies

StringCollection Setting Throws Exception?

Dec 10, 2011

For Each ScreenName As String In da.settings_LinkedScreenNames

View 5 Replies

How To Get Text From Sql Server Image Field Into StringCollection

May 5, 2009

I am Delphi programmer and I am new in .Net VB code to get text from sql server image field to StringCollection, in Delphi I use code:

MemoryStream := TMemoryStream.Create;
BlobStream := SomeQuery.CreateBlobStream(SomeQuery.FieldByName('MY IMAGE FIELD NAME'),bmReadWrite) as TBlobStream;
BlobStream.Position:=0;
MemoryStream.LoadFromStream(BlobStream);

[Code]...

View 1 Replies

Create A StringCollection Setting And Manually Enter Some Data?

Jan 16, 2008

I have used My.Settings for quite some time now, in both VS2005 and now in 2008, but never noticed this behaviour yet... I must be forgetting something trivial? I create a StringCollection setting and manually enter some data (strings).I write some code to handle this, and I get it to work.

Then, I manually add some new strings (and edit the older ones) in the Settings page, save the project, and run my code again.For some reason, the last changes have not been saved... Whenever I look in the settings page, I see them there, but my code cannot recognize them..

[Code]...

View 12 Replies

Populate System.Collections.Specialized.StringCollection Object From A Text?

May 6, 2010

Say I have a text file I want to load it to a System.Collections.Specialized.StringCollection

object dim a as System.Collections.Specialized.StringCollection

set a = a contains many systems System.Collections.Specialized.StringCollection object.

Each line in text.txt go to an element in a.

View 7 Replies

Convert A String Containing A Binary, Octal And Hex Number Into A Decimal String?

Jun 7, 2009

I'd like to convert a string which contains a decimal number into string that contains the binary value, the octal and the hexadecimal value of that decimal number.Afterwards I also like to convert a string containing a binary, octal and hexd. number into a decimal string.Basically I'm looking for the functions:

dec2bin
dec2oct
dec2hex
bin2dec
oct2dec
hex2dec

I'd not prefer to rewrite a function, I'm sure the framework must have these functions already.

View 5 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved