Question Obtaining Characters from a sting with the specified character positions in .ini

stork1990

New member
Joined
Sep 23, 2014
Messages
1
Programming Experience
1-3
Here's my situation:

The application determines parts required based on a 20 character string supplied. There are 3 part types with say 20 parts per type.

For each of the part type I only need to look at certain characters in the 20 character string(IE char 1, 5, 10 and 18).

I would like to be able to specify the character positions for each part type in the ini file and use that to parse the required characters from the original 20 character string.

Im drawing a blank on the most efficient/logical way to accomplish this... Any Ideas??

Thanks!!

-Matt
 
First, do you need to use an .ini file or were you just looking for some external text-file that can be easily edited before running the program? If the latter, then I'd just use the VB.Net Settings for your program (eg ProgramName.exe.config file)... VB.Net already has easy ways of reading values from these files, and they are XML files (which are text based, so can be opened with just Notepad in order to change the values).

Also, are there always 4 positions to look at or is that dependent on different 20-char. strings? If there is a fixed number of positions, then you could have a separate setting for each position. If however there will be an arbitrary number of positions, then perhaps create a "super variable" that contains multiple values separated by some delimiter character (eg using your example "1|5|10|18" as the value of your setting), and then use the Split() function to separate the different values into an array that you can then iterate over.

Finally use the Substring method to get the substring of the 20-char. string, using two of the position numbers to determine the positions to start and end the substring.
 
I'd tend not to use an INI file for anything .NET if possible. Regardless, once you have your text in your app, a String can be treated like an array of Char in many ways. As such, you can simply index the String to get particular characters, e.g.
If myString(9) = "A"c Then
    'The tenth character is an upper-case A.
End If
Note that, just as with any list in .NET, a String is zero-based, i.e. the first character is at index 0.

Also note that a Char literal is a single character wrapped in double quotes and followed by a lower-case c. That is NOT a String containing one character. It is specifically a Char. If you put more than one character inside the quotes it will not compile.
 
Back
Top