How do do a sub string in an INI file - ini

I have a variable called COUNTRY in an INI file. However, I am trying to get the last 5 characters from he value of the variable.

Related

How to paste a DIC file without deleting the default file or overwriting existing content with Go?

I want to check the characters of a file sequentially from the beginning of the file and if a character exists in file1 and not in file2, It appends the character.
Actually I have a DIC file that I want to install on the user's computer. But I don't want existing texts to be overwritten. Also, I don't want to delete the default file on the user's computer.
This DIC file is a screen reader dictionary used for the blind.
I would be grateful if you could help me
I wrote a code that checks the character, but I couldn't write it to the file.
This is my code: https://go.dev/play/p/4ogdlQaBRHz
Note: This code may be a incorrect code.

How to scan one part of a file as a variable

I'm a beginner and I have a code that requires me to scan the last number of a file into the variable a.
The file looks something like this:
car,4,50,800
If I want to scan the "800" into the variable a, how do I do that?
In order to do it you have to read the data first and find the last occurance of the ',' char. Then you can get the data till let's say the end of file (EOF) or the new line char (\n). 8t all depends by the protocol you are using to store your data.

how to retrieve specific value from file using Python

i have a text file which contain several lines in the end of the file I have the following line: "Total: 235267878"
my question is: How do I retrieve the specific value (235267878) and set it to a variable?
Thanks!
Since you didn't specify how long your file can be, we can iterate through the file:
with open('test.txt', 'r') as file:
for line in file:
if 'Total:' in line:
totalValue = line.split(':')[-1].strip()
print(totalValue)
In this solution I assume that the line we are looking for always has the form Total: {number}. We open the file in the read only mode and iterate through the lines (In my exmaple the file is called test.txt). After the line containing the total value is found, we split it and remove possible white spaces to get the number. The variable totalValue contains the number you are looking for.

Why is powershell giving an incorrect length of this array

I have read here that when we read in the contents of .txt file using the get-content cmdlet into a variable, it is saved as an Array:
When Get-Content reads a text file and stashes the contents in a
variable, the data is stored as an array, with each line in the file
(determined by the presence of a carriage return-linefeed character)
representing a single item in the array.
I read in the contents of the text file using get-content, and 4 lines were printed to the powershell console.
Then I read in the contents of the same file into a variable ips, and then used the ips.length as well as ips.count, 7 was printed out.
What am I missing?
There is a blank line at the top and two at the bottom of your content. These, plus the four lines of content = count/length 7

Comparing a string from text file and then printing out the entire line(s)

My goal is to print out every full line from a text file if that line contains a string that is equivalent to user input.
I understand how to find the occurrences of a specific string in a text file, but I am confused as to how to associate that with a specific line. How do I relate my string with the specific line that it is in?
My initial thought was to store each line in an array and then print out that line if the user string is somewhere in that line.
However each line is a different size, so I was wondering if it is possible for me to initially divide my entire text file into x number of lines and then use a loop to go through each line and search for that string?
Save the file pointer of the starting of the line in a temp variable before starting new line compare

Resources