Compare text in single string

can anyone point me in the direction of how to compare text inside a single string. What I need to achieve is if the same wording appears more than once in the same string I then need to be able to shorten that string by taking the replication of the word out. i.e. ‘the cold weather is cold’ Shorten to : 'the cold weather is ’ Any ideas ??

Or should the answer be… ‘the weather is cold’ Clearly you need to identify the rules that define a word and the instance that is the repetition? Is a word enclosed between 2 space ? Is the second instance the repetition? … Repeat Find next word. Save pointers for position of word in string. Search the rest of string for word. IF word found then rebuild source string until end of string

I had thought of that one too, but I didn’t want to have to make it THAT extreme [V] Never mind, looks like I will have to go with it unless someone comes up with another solution [?]

Hello Dean, apart from the technical solution, I am dying of curiosity. Please explain why you need this functionality in an accounting package like Navision! Thanks in advance Pelle

You could try the following solution, which is possibly a bit easier to implement and should run faster: 1) Scan the string from left to right, breaking it up into words at whatever boundaries you might have defined (blanks, periods etc.). This requires a single pass using two pointers. 2) Store each word you find in a separate data structure, if it’s not already stored in this structure (this will get rid of the duplicates). 3) Retrieve all words from the data structure, thus creating the final result. Now, point 2) is not trivial. Depending on your needs and programming environment, this could be anything from a simple array over a hash table up to a Navision table. A hash table will provide faster access, but you won’t get the words out in the order you stored them (which might not be a requirement). Besides, implementing a hash table in C/AL will be a bit tricky [xx(]. An array will provide for ordered output, but is limited in size and requires linear search during looking up if a word has already been found. A Navision table storing just text strings (a temporary record variable will suffice) is probably the easiest, fastest and most flexible way, but eats up a table number in the object designer.

Heinz’s idea of using a temporary table is quite nice. You could use Table 5117 Search Word as the temporary table and avoid eating up a new table for this purpose alone.


Originally posted by xorph
A hash table will provide faster access,

What’s a hash table? [:I] Anna


Originally posted by Anna Perotti
What’s a hash table? [:I]

Hello Anna, A hash table is a data structure where stored elements are indexed by a number derived from the elements themselves. The English word “hash” means to grind into small pieces, like the German “faschieren” (sorry, no parlo Italiano [;)]) - this refers to the way the index values are calculated from the elements. To illustrate this abstract definition with an example: Let’s say you want to store people’s names in a hashtable. You create an ordinary array of string, and then, for each name stored, calculate the binary XOR of the ASCII values of the name’s letters. This will be the index of the name in the array (the “hash code” or “hash value” of the name). Of course, you can extend this table to store entire records of personal data. If you later want to look up a certain name and the associated information, all you need to do is calculate the hash code for the name you want to search for and look up the element in the table. This is very fast and beats every other search method (linear & binary search). Of course, there’s a lot more to it than I can describe here. The hash function must be carefully chosen (XOR is not always your friend), and you have to consider the case where two different names yield the same hash code and therefore would be stored in the same location. There are several (well, I know of two [:p]) methods to deal with this. If you are interested in more details, we can continue via email, if you like. I’m also pretty sure that you will find lots of information in Google. Hash tables are a convenient and fast data structure for all kinds of information and are e.g. heavily used in chess programs (which happen to be the topic of my dissertation [:D]).


Originally posted by xorph [ Hash tables are a convenient and fast data structure for all kinds of information and are e.g. heavily used in chess programs (which happen to be the topic of my dissertation [:D]).

Have you considered working in the video game industry ? [;)]


Originally posted by Tarek Demiati
Have you considered working in the video game industry ? [;)]

Only if I could create a chess game which can be played in first-person-shooter mode [:D] Joking aside, the video games sector is too close to the machine for my taste. I don’t like specializing on a specific chipset…