Javascript - Getting The Closest String Match
May 2, 2011
I need a way to compare multiple strings to a test string and return the string that closely resembles it:
TEST STRING: THE BROWN FOX JUMPED OVER THE RED COW
CHOICE A : THE RED COW JUMPED OVER THE GREEN CHICKEN
CHOICE B : THE RED COW JUMPED OVER THE RED COW
CHOICE C : THE RED FOX JUMPED OVER THE BROWN COW
(If I did this correctly) The closest string to the "TEST STRING" should be "CHOICE C". What is the easiest way to do this?
I plan on implementing this into multiple languages including VB.net, Lua, and JavaScript. At this point, pseudo code is acceptable.
View 8 Replies
ADVERTISEMENT
May 7, 2012
I have a scenario at work where we have several different tables of data in a format similar to the following:
Table Name: HingeArms
Hght Part #1 Part #2
33 S-HG-088-00 S-HG-089-00
41 S-HG-084-00 S-HG-085-00
[code]....
Where the first column (and possibly more) contains numeric data sorted ascending and represents a range to determine the proper record of data to get (e.g. height <= 33 then Part 1 = S-HG-088-00, height <= 41 then Part 1 = S-HG-084-00, etc.)
I need to lookup and select the nearest match given a specified value. For example, given a height = 34.25, I need to get second record in the set above:
41 S-HG-084-00 S-HG-085-00
These tables are currently stored in a VB.NET Hashtable "cache" of data loaded from a CSV file, where the key for the Hashtable is a composite of the table name and one or more columns from the table that represent the "key" for the record. For example, for the above table, the Hashtable Add for the first record would be:
ht.Add("HingeArms,33","S-HG-088-00,S-HG-089-00")
This seems less than optimal and I have some flexibility to change the structure if necessary (the cache contains data from other tables where direct lookup is possible... these "range" tables just got dumped in because it was "easy"). I was looking for a "Next" method on a Hashtable/Dictionary to give me the closest matching record in the range, but that's obviously not available on the stock classes in VB.NET. what I'm looking for with a Hashtable or in a different structure? It needs to be performant as the lookup will get called often in different sections of code.
View 3 Replies
Aug 18, 2010
So there's this accounting package at my client that spits out text-based reports with invalid dates, like February 31st or September 31st.The reports are formatted with spaces and mono-spaced fonts. The data that gets parsed out are fed into a more formal local SSRS report, and that's about all you need to know.
What I am interested in fixing is the situation where a date is invalid and can't be converted into a DateTime struct. The date format from the report is "MMM-dd-yy" (e.g. "Feb-30-10"). The date strings need to be fixed before being shown in the formal report. I've seen this done two ways in my time as a developer, and I want to come up with a cleverer way of doing it (if there isn't a built-in way I don't know about).The first bad method (I can't believe I'm even showing you!):
Dim month As Integer = <Parse out the month from the bad date string>
Dim day As Integer = <Parse out the day from the bad date string>
Dim year As Integer = <Parse out the year from the bad date string>
Dim validDate As DateTime
[code]....
View 1 Replies
Oct 8, 2009
The database field has text inside the field and I want to match it with another string...How do I convert a field to a string?
View 7 Replies
Jun 9, 2009
Im trying to work out what the best way to match 2 strings together, but with a difference.
String1 = "dog cat bird chair book table"
String2 = "the dog chassed the cat around the chair"
No I know I can break string1 up by space character and check if each word appears in string 2, I would prefer to not have to do that.If there some sought of regex that would take a group of words and retrun how many of them matched ?
View 2 Replies
Aug 1, 2011
I have :
[Code]...
I think I have explained my problem properly..
View 2 Replies
Apr 18, 2011
I'm currently trying to match a word in a string - to a word in an 1 dimensional arrray.
So it does this.
1.Goes into array, gets first word.
2.Looks for that word in the string.
3.If can't find it, go to next word in array.
4.And so forth until it finds it or runs out of words in array.
Problem is the string can be upto 2000 characters long. And the Array with the possible matches can have upto 8000 entries.
So when it runs, if the word begins with 'A' it finds it dead quick as the 'A's are at the top of the array, ordered alphabetically. This is great.
But if the word starts with 'Z' then it takes 4-5 seconds before finding it.
I'm basically using InStr to find the word in the string.
View 5 Replies
Jun 9, 2011
how to check if the user input has a match in my given string
Dim a as string
a = "abc"
if the user input in the textbox "erty" the message box will be shown string not found. if the user input 123abc the message box will be string found
View 3 Replies
May 18, 2012
I am making a question and answer game, and I would like to be able to give the user some slack in the answers if they were to misspell a word by a letter or two, like if the answers was Jumps and they type Jump if you did a comparison of them like If string1 = sring2 then do whatever, but obliviously those to string dont match, so it would return false, even though it is the right answer, I came up with this routine to compare two words and if the percentage of the letters are higher then 82 % right it will give you credit for your answer.
[Code]...
View 7 Replies
Nov 21, 2010
i have a string named Workers that had multiple lines of text. I need to search those lines for the term "BackGroundWorker1" if it is found then do something if not do something.
View 3 Replies
Feb 21, 2012
I am not a regex guy, so I need a little help, just cant get my head around this...
I am writing registration page and using asp.net validators. I need a regex validator to match a special character anywhere within a word, so it will satisfy requirement which says that "ID must have at least one special character." Allowed characters are[code]...
Once again, I am a junior, and having problems with wrapping my head around this stuff at this moment..
View 4 Replies
Jul 2, 2009
I want to match a string for example "yes" but where it is not in brackets so that the following would be matched: yes (bla yes bla) bla yes
View 7 Replies
Jul 2, 2009
I want a regular expression for the following issue:I want to match a string that contains A,B,C,D,E and F. string length should be 0 to 6. and not character should be repeat in the string.Example: ABCDEF, ACDEFB, EFBCDA, etc. but not ABBCDES/W Engineer
View 3 Replies
Aug 11, 2011
I have a simple string : s:10:"char1";s:2:"13";i:1;a:8:, i'd like to match that 13 from inside " ", in PHP i would do something like :
/s:dd?:"char1";s:dd?:"(.*?)";i:dd?;a:dd?:/i but i'm not good in vb's match methods,so please give me full example how i can match what i need ( it is possible to be multiple matches (2) ).
View 1 Replies
Sep 30, 2011
I'm trying to replace a string with another but the problem is that the string is matching some other string partially.
For e.g. -
Dim x as String = "I am Soham"
x = x.Replace("am","xx")
After this replace I would only like the word am to replaced with xx but because my name also contains am its also getting replaced.
View 2 Replies
Nov 18, 2009
I'm looking for a way to search a string variable for two words and copy the text in between them into another variable. This needs to be done as many times as the match occurs.
View 3 Replies
Dec 11, 2009
new with Linq and very excited with this feature. However, I want to see if I can do the following with LINQ:
[code]...
Notice that I have a break in my foreach loop, meaning that I just need to reset the first match row's column value to empty string.
View 4 Replies
Aug 14, 2009
How can i filter a DataView to a string nearest match? Almost like a FullTextSearch, is this posible using a DataView?
View 1 Replies
Dec 2, 2011
Well my question is simple, I want to match a string with following attributesNo white spaceMust start with a letterMust not contain any other special characters other than nderscore
View 2 Replies
Jul 7, 2011
I have a function that is getting passed a String and a DataRow.The String is a custom formatter. The idea is to do this
String.Format(passed_in_String, DataRow("ColumnINeed"))
The reason this is being done is at this point we have no idea what the column contains.However, if the formatter is "{0:MM/dd/yyyy}" and the DataRow("ColumnINeed") is an integer containing 42, String.Format is returning: MM/dd/yyyy In this situation I need it to throw an exception instead of returning nonsense.Is there anyway to make String.Format throw an exception if the object does not match what the format string is expecting?
View 2 Replies
May 30, 2010
I have a text file contains " staff id, male/female, first name+surname", which look like this[code]...
1: i dont know how to display a error message if the text file is not found
(i can display all the staff's in listbox with one click)
2: i need to display "male" only in the listbox.[code]...
View 14 Replies
Jun 29, 2012
[Code] Which (when looped) checks all items that contain X, However, I am getting a lot of false positives (i.e. if PGA is legit, PGA, LPGA, JLPGA, WHATEVERPGA will all be highlighted as well) Any way to change .indextof to an .exactindexof or something?
View 1 Replies
Apr 20, 2011
Heya so im close to be done with this project but unfortunately i still have a couple of questions ill start with the first, imagine this listbox contents:
[Code]...
Now imagine theres a string with : "2-12-2009 | 11:30"How can i delete a listbox item if the string matches the listbox item text after the arrow?It might sound a bit confusing but what im planning to do is to delete a listbox item based on the date of the event and not the date of the alarm.
View 6 Replies
Apr 18, 2011
I have been trying to solve this with no luck. If i have an array Private _msg() As String = {"You have been successfully logged in.", "This message has been sent successfully.", "This message has been posted successfully."} And a string (page source) can LINQ try to find any of the Three elements in the array with out having to use a loop?
View 11 Replies
Jun 24, 2009
I am pulling a random name from my database that matches up with images (embedded images) in my project.[code]
View 2 Replies
Jan 4, 2012
I want to match whole words for any kinds of strings, my
Text: to happening behitond .to.the to curtains of this .<NET> open <NET> sou<NET>rce project.<NET>
now i have tried this to find "<NET>" (without quotes) the whole word with[code]...
View 3 Replies
Jan 5, 2011
ive got a small code which takes a strign given by the user, searches for all folders with in a folder for matches then lists them, which is this:
vb
If e.KeyData = Keys.Return Then
Dim lb1s As String = Application.StartupPath() ''The folder to search in
[Code]....
The results are added to a listbox and all works great, but how do i get it to add partial matches aswell? For example if the search string is 'testing' and theres folders called 'testing on' 'testing testing' etc to show those in the results aswell?
View 4 Replies
May 29, 2010
Am trying to match characters or combination of the characters i specify in any order they appears
vb
Regex.IsMatch(teststring "[nuls]")
what i want matched is either any single character, or combination of any of them in any oder. this means that it should not match any character not specified in the pattern.
For example
it should match
n,u,l,s,nu,un,lun, sl etc
not
ny, nx so etc or any other
View 9 Replies
Jun 27, 2012
I am trying to match words driven from a database in a string input using VB .NET
The syntax I am using is so simple:
[Code]...
View 1 Replies
May 21, 2009
searching through memory at a given address range, and match a string of bytes specified i.e.
FindArrayOfBytes(Byval str as String, Byval range_start As Integer, Byval range_end as Integer) As Integer
The function should return the address start of where the array of bytes was found.
View 7 Replies