.net - Dictionary Access: Composite Key Vs Concatenated String Index?

Jan 31, 2012

I have a dictionary that I want to access with a key that is the combination of a string (AcctNum) and a date (BalDate).It seems to me the simplest approach is to create the key by simply converting the date to a string and concatenating:MyKey = BalDate.ToString & "|" & AcctNum

I know I also have the option of creating a composite key by writing a separate class and overriding GetHashCode() and Equals() a la this solution. To me, the concatenated string is a simpler, if somewhat less elegant, solution. Am I missing some compelling reason why I should go with the composite key class approach?

This lookup is the crux of the project I am working on, so performance is my main objective (with readability a close second).

View 2 Replies


ADVERTISEMENT

Traverse A Concatenated String?

Jan 17, 2011

I have a concatenated string like...

str= 1010,5050,6079

And want to separate the string In Javascript I can do

string = Srt.split(","):

and the result...

string[2]=5050

Is there a way to do this in VB.NET?

View 2 Replies

Access A String (index) In .Net 1.1?

Dec 1, 2009

I have converted this existing C# .NET 2.0 code (which appears to take in a string with any characters and return only the numbers in that string):

private static string StripMIN(string min)
{
string result = string.Empty;
int digit = 0;

[code]....

I am getting an error message on line 6 of the VB.Net code at min(i). The error message reads:

"Expression is not an array or a method, and cannot have an argument list"

View 3 Replies

Output Name Using String Manipulation / Concatenated

Aug 15, 2011

I'm suppose to end up with a label box with my name spelled out in it using string manipulation. This is suppose to happen using the concatenated string to output the name into the label box. I don't have any error codes but I also don't have my name in the label either. [code] "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. [code]

View 2 Replies

Saving A Concatenated String For Next Startup?

Feb 21, 2011

For my application, there is a login form in which users have the option for it to "save the login information" Kind of like MSN or other websites in which you go to a login page an the information is filled out. On my login form, I am using this code for my checkbox which is to "save login info"

Private Sub CheckBox1_CheckChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.Click
Dim s As New System.Text.StringBuilder

[Code]....

View 4 Replies

VS 2010 Parsing Concatenated String?

Jun 25, 2011

I am writing a tool that logs stats for a first person shooter game. The game writes its information (including who killed who with which weapon) to a log file, which I read every so many seconds and parse so that I can write that information to a database.I am now having trouble parsing the weapon out of that string of information.

Some additional information is required: a weapon in this game can contain attachments (such as a scope, a grenade launcher, etc). Weapons can have either 1 or 2 attachments. Some weapons however cannot have any attachments at all.

Each log file entry that describes a kill contains a code that describes the weapon that was used. This code is a concatenation of either 3 or 4 parts:

<weapon>_<attachment>_mp
<weapon>_<attachment1>_<attachment2>_mp
where <weapon> is a code that describes a weapon and <attachment> is another code describing the attachment.This should be easy to parse by just splitting along the underscore characters, but there's a few catches:

1. Some attachments are able to kill players as well. Specifically: grenade launchers, flame throwers and underbarrel shotguns. In this case, the attachment is listed before the weapon:

<attachment>_<weapon>_mp Note also that in this case there is always only 1 attachment.

2. The biggest catch: some weapon names have an underscore in them (some even have 3 underscores)! So simply splitting along the underscore won't work in all cases; if the weapon name contains an underscore I'm splitting the name of the weapon..This makes the list of possible combinations a lot longer. The ones I can think of (I think these are all):

[Code]...

View 10 Replies

Forms :: Create Concatenated String As Name For New Textbox?

Jul 13, 2010

I am trying to programatically create textboxes in my app. I need to do this:

dim textbox(x) as new textbox

x needs to loop 1 thru 10 but I can't get VB to accept my coding.

View 2 Replies

Asp.net - Auto Suggested Text Box With Concatenated String With LINQ To SQL

Dec 8, 2009

I'm creating a text box with auto-suggested. So, it works well. It suggests only first name, but I want it to suggest the full name (first and last name which two different columns). Take a look at the following code behind that worked as expected :

[Code]....

View 1 Replies

Linq - Create A Concatenated String From A List Of Objects In 3.5?

Apr 27, 2012

I figure I should use 'Aggregate' but apparently I am getting it wrong First I get a list of my Entity objects Dim employers As List(Of myEntity) = (New XXXX()).getZZZ(userName, userType) Then I figured this would be a way to put all the names in a string Dim names as String = employers.Aggregate(Function(current, [next]) current.Name & " " & [next].Name)

[Code]....

View 2 Replies

Finding The Index Of A Key In A Dictionary?

Dec 5, 2010

I am trying to find a record within a nested Dictionary, so that I can add more records to the sub-Dictionary.

The intention is to be a dynamic configuration, where no matter what I pass into it will group into like item categories that have already been added. If there are no like items it will add a new category.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim xConfig As New Dictionary(Of String, Dictionary(Of Int64, Object))

[Code].....

View 1 Replies

Seek Key Of Dictionary By Index Value?

Dec 17, 2010

How can I get the key of a dictionary by passing the index value? I'm trying: If rs.Fields("NM").Value = dictNM.key(0) that is, I want it to compare to the first key in the dictionary but I get the error Compile error: Invalid use of property I tried googling, but to no avail. I'm hoping this is even possible.

View 1 Replies

Retrieving The Index Of A Key In A Dictionary(Of Tkey - TValue)

Jun 15, 2011

Is it possible to retrieve the index number of an item/key in a Dictionary(Of TKey, TValue) object?

View 13 Replies

Iterate Through The Keys And Values Collections Of A Dictionary Object Using An Index?

Apr 25, 2009

I have a VB.NET project where I am able to iterate through the keys and values collections of a dictionary object using an index:

MyDictionary.Keys(idx)
MyDictionary.Values(idx)

When this code is taken from the test project and placed into the real project I get the following error:

'System.Collections.Generic.Dictionary(Of Double, String).KeyCollection' cannot be indexed because it has no default property.[code]...

In the line in sub search that says "dtf.Keys(idx) = 0" place your cursor after the right parenthesis and backspace you should get a tooltip that says, "<Extension> ElementAtOrDefault(index as Integer) as Double - index: the zero based element of the index to retrieve.

View 3 Replies

Difference Between Dictionary(Of String, String) And IDictionary(Of String, String)?

Jan 18, 2011

Can I do anything more or less with IDictionary? How do these two collections differ?

View 5 Replies

.net - Can't Return Dictionary(Of String, String) Via GET Ajax Web Request, Works With POST

Jun 23, 2009

I have the following web method:

<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=True, XmlSerializeString:=True)> _

[Code].....

I wanted to use HttpGet here so that the result can be cached.

I tried every variation of calling this, but no luck. Is this possible with GET?

View 2 Replies

C# - Is There A Difference Between StringDictionary Class And Dictionary<String,String>

Mar 20, 2011

System.Collections.Specialized contains StringDictionary

[url]...

What's difference with Strong Typed Dictionary in Generics?

View 1 Replies

VS 2010 - Does Have Access To A Real Dictionary

Dec 26, 2010

I just want my program to use random english words in some task and I was wondering if vb.net has access to the OS's english dictionary?

View 2 Replies

Access Generic Dictionary Contained Or Nested In Another One?

Nov 17, 2009

I have a Generic Dictionary contained or nested as a child in another Generic Dictionary. I need to be able to access the child dictionary objects by key. When I attempt to do this I get the following error:
"Value of type 'System.Collections.Generic.KeyValuePair(Of String, String)' cannot be converted to 'System.Collections.Generic.Dictionary(Of String, String)'."

So it seems that the contained Generic Dictionary is being returned as a Generic KeyValuePair when accessed via a key as opposed to iterating through the parent dictionary in a For/Each loop.

The first section of the sample works OK (using a key to access a string value in a dictionary).
The second section of the code works OK (iterating through the dictionary values in a For/Each).
The third section of the sample is where the error occurs (using a key to access a nested generic dictionary...see underlined code).

Dim td1 As Dictionary(Of String, String)
For Each thisKey As String In td1.Keys
Debug.Print(td1(thisKey))
Next
Dim td2 As Dictionary(Of String, Dictionary(Of String, String))
[Code] .....

View 1 Replies

Doesn't Anyone Use Dictionary Member Access Expression

Dec 4, 2009

Doesn't anyone use the dictionary member access expression? (a.k.a. the bang operator) If so, in what scenarios? url...

View 1 Replies

Write Dictionary Or String To XML?

Jan 15, 2012

I am looking to write the contents of a dictionary to XML. I have written the dictionary contents to a string as i have been told it is easier to write from a string to XML instead of from a dictionary. But im not sure if this is correct?

Is there any way to write this to XML from the dictionary or string?

View 1 Replies

Performance Of Dictionary(Of String, SomeReferenceType)?

May 17, 2009

How does performance for reading/adding values from/to Dictionary(Of String, omeReferenceType) depend on the number of records already entered? I mean, does timeincrease as O(1), O(log n), O(n) when n goes to be large, or in some other way?

Dim index As New Dictionary(Of String, SomeReferenceType)
' N entries added in a loop
' ...

[code]....

View 2 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

Sorting - Sort List(of String()) Using A Variable Index Into String() As Key ?

May 30, 2012

I have a List(of String()). I have written a custom comparer (implements IComparer(of string)) to do an alphanumeric sort.Is there a way to sort the List using a given index to determine which position in the String() to sort by? In other words one time I might sort by Index = 0 and another time by Index = 3. The length of all String() in the list is the same.For reference this question is similar to Sort List<String[]> except I am using VB.net and that question is hardwired to Index=0.

EDIT from OP's comments:I started simple with the non custom comparer but I am getting an error: expression does not produce a value. Not sure what I am doing wrong.Here is the code:

Public Shared Function SortListOfStringArray(ByVal ListOfStringArray As List(Of String()), ByVal SortByIndex As Integer) As List(Of String())
Return ListOfStringArray.Sort(Function(x, y) x(SortByIndex).CompareTo(y(SortByIndex)))
End Function

View 1 Replies

Convert A String Of Key / Value Pairs To HashTable Or Dictionary Or?

Jun 19, 2010

In VB.NET, how can I convert the following string into some kind of key/value type such as a Hashtable, Dictionary, etc?"Name=Fred;Birthday=19-June-1906;ID=12345".I want to extract Birthday or ID without having to split the string into an array.I'd prefer not to split the string into an array in case the format of the string changes later.I don't have control over the string.What if someone switches the order around or adds another element?

View 6 Replies

Dictionary Of String - After Filling Readout Always Empty

Mar 12, 2012

I need to do some comparing and shuffling of fields, (I come from a more PHP background and working with arrays is completely different, as suggested after reading many things here I know VB.NET uses list and Dictionary easier. I have a dictionary (of string, dictionary (of string, string)) which is filled well, but after I try to read it out, it's always empty....

Below I fill a few things. The var I am talking about it
fillDictionary inside the matcheswholename VALUES part.
I fill up the fillDictionary and add it to the matchesWholename
After which I clear it, because it is in a loop and more is to come.

Dim matchesTotal As New List(Of String)
Dim fillDictionary As New Dictionary(Of String, String)
Dim matchesWholename As New Dictionary(Of String, Dictionary(Of String, String))
Try
If ds.Tables("matchesWholename").Rows.Count > 0 Then
For Each dr As DataRow In ds.Tables("matchesWholename").Rows
[Code] .....

When later I try to readout like this, it returns nothing....I am actually sending a copy of the filldictionary into it or not? or does my clear() method clear what's inside it?
Dim pair As KeyValuePair(Of String, Dictionary(Of String, String))
Dim subpair As KeyValuePair(Of String, String)
For Each pair In matchesWholename
' Display Key and Value.
For Each subpair In pair.Value
Console.WriteLine("{0}, {1}, {2}", pair.Key, subpair.Key, subpair.Value)
Next

View 1 Replies

String - Write The Contents Of A Dictionary To A Message Box?

Jan 9, 2012

This code has changed and will be applied to another question

View 3 Replies

Write The Value Of A Dictionary To A String, Where There Are Multiple Items Associated With Value

Jan 12, 2012

I was wondering if it is possible to write both the dictionary key and all records associated with the value to string?

However i only get the output of the Key and one item in value (service status)

View 1 Replies

Use Linq ToDictionary To Return A Dictionary With Multiple Values In The Dictionary Items?

Jan 25, 2010

I want to group items from a linq query under a header, so that for each header I have a list of objects that match the header title. I assumed the solution would be to use ToDictionary to convert the objects, but this allows only one object per "group" (or dictionary key). I assumed I could create the dictionary of type (String, List Of()), but I can't figure out how to write it. As an example I have written a simplified version below.

[Code]...

View 2 Replies

Variable Lists In Dictionary (String / Boolean And Integers)

May 5, 2011

So I had a smart idea to make a dictionary with all my variables so I could save them easily in chunks. This includes String, Boolean and Integers. When I was in Framework 3.5 I only had a few warnings about stuff that I didn't have coded in, but now in Framework 4 I am maxing out all my warnings with Implicit conversions. Personally I don't want to go to every number and put quotes around it put quotes around "True" because then it may change the method.

Public Function loadGeneral(ByVal fName As String) As Boolean
Dim tempDict As New Dictionary(Of String, String)
For Each kvp As KeyValuePair(Of String, String) In GeneralSettings
Dim v1 As String = kvp.Key
Dim v2 As String = QuizZing.My.Settings.GetSetting(fName, v1)
[Code] .....

View 14 Replies

Dictionary In A Dictionary - Collection Of Data To Pass Back ?

Apr 27, 2009

I have created a class with a function in it. I have a collection of data I want to pass back. I tried an arraylist first. Now I am trying to use a dictionary. My problem is that it creates the dictionary ok, but I am only get the last row of data from my

Function GetWeldAuditInfo(ByVal ResourceId
As
String,
ByVal VendorId

[CODE].........................

View 2 Replies







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