How can I use this blank space in an if statement? - if-statement

I am new to programming and I am trying to scan in strings from a text file and assign each string to variables but some lines in the text file have 4 variables I need to assign but others only have 3. On the lines that only have 3 variables I need to assign what would be the 4th variable a value without assigning it the first string in the next line. I managed to get to the point where it assigns all the variables correctly except for the would be 4th variables on the lines with only 3 variables for me to assign. on these variables it assigns them a blank space but no matter what i try I cannot compare these blank spaces in an if statement to assign them the correct strings.
This is the code I have.
This is the text file I am scanning.
I have checked value stored in these variables and they are not null it shows a blank space but whenever I try " " or any escape characters it does not work.

Related

C++ Reading and printing newline characters from a file

I am keeping a large repository of strings in a character-delimited file. Currently, I am reading the strings into string variables, and then later printing them.
The problem I'm facing is how to store and print new line characters. In the file, if the string, for example, is:
"Hello this is \n\n a new line"
then the literal '\n' is printed in my program terminal when I print the string, however I would like to print new lines.
Is this a matter of processing the strings character by character, or is there a proper way to read the strings into the string variables that will allow this to work?

Incrementing Integer Inside Lines of a Text File

I have large text files with about 6 lines/instances of 3_xcalc_59 in which 59 is some 2-digit integer.
I am looking to increment these values of the text file by 1 every time I run the program.
I know I can increment a value defined in the code, but how can I increment an integer inside a line of text?
I was thinking the first part of the process would involve reading these lines and assigning them to string variables or a list, but I am not sure how to even do that.
I can find the lines by writing if line.startswith("3_xcalc") , but I'm not sure how to assign them to a list.
Simply writing
for line in open(inputfile, "w"):
line.startswith("3_xcalc") = listoflinesstartingwith3xcalc
Tells me "can't assign to function call", so that doesn't work, but I'm not sure what else to try.
Thank you.

Parsing a tab delimited text file

I'm trying to parse a text file from one format to another. The text file is delimited by tabs. The text file I'm using as test has as of now three types of lines. For example, the first line of the text file has an H in the beginning. Since I do not need it now, I ignore it and pass to the next line. Similarly, I have lines that start with S and L. The S lines have five strings, including the first character, which are read by:
while(std:: ifstream readFile >> string1 >> string2 >> string3)
Below this while I have an if statement to check every S at the beginning of each line, which is as follows:
if(string1[string1.length()-1]=='S')
Then I print in the console each value to make sure every line which has an S is being printed in the console, but it's not. It's showing n - 2 where n = total of lines containing S at the beginning. I should also mention that below print statement, I also have this: std::getline(readFile, string1); without this, it shows me n - 5, if I'm not mistaken.
Also, when I only use two parameters while instead of three, all lines are shown with the first two strings, but as soon as I pass three parameters it changes back to n - 2.
What could be the problem that whenever I pass more than two parameters, it does not show me every line that contain S at the beginning(specifically the first two).
Thanks, and sorry if not explicit enough.

Cannot delete non-space whitespace character in excel

When bringing in data into excel via whatever method (import, paste, ...) I sometimes get the following issue. At the beginning of the cell there is an extra space in front of the text. Now I know the usual procedures to handle this namely:
trim(cell number)
and if its not a space character
=TRIM(SUBSTITUTE(cell number,CHAR(160),CHAR(32)))
But this time both of these didn't work. I did try other substitute CHAR's.
AND the character at the beginning is just plain weird. When I go to the very beginning of the cell and try to delete it I must hit the delete key twice to remove one space! But when I go to the first character in the cell and instead hit backspace I only need to press it once.
What else can I do to eliminate this weird non-space whitespace character?
If cell A1 contains non-visible junk characters, you must identify them before you can remove them.
Pick some cell and enter:
=IFERROR(CODE(MID($A$1,ROWS($1:1),1)),"")
and copy down. This will give you the CHAR code for each character in A1
Then you can use SUBSTITUTE() to remove the offender.
Lets assume column A has text where some cells are good and some have text with the weird space like character at the front. So some cells we want to change and some we don't.
1) Create a one column table with one letter in each cell. I decided to go over to the right to column H for the table. So for example cell H1 has A, cell H2 has B and so on.
2) Get the length of the cell we want to edit. I've put this formula in cell B1.
=LEN(A1)
3) Test the cell for the first letter. This gives us which cell to change and which not. I've put this formula in cell C1.
=ISNA(VLOOKUP(LEFT(A1),$H$1:$H$26,1,0))
4) Change (or not depending on step 3) using RIGHT and the result from LEN.
=IF(B1,RIGHT(A1,B1-2),A1)
Notice that I have to subtract 2 spaces and not one? Like I said it was a strange character.
5) Repeat down the column.
If the first legitimate character in your string will be in the set [A-Za-z0-9] then you could use this formula:
=MID(A1,MIN(SEARCH({"a";"b";"c";"d";"e";"f";"g";"h";"i";"j";"k";"l";"m";"n";"o";"p";"q";"r";"s";"t";"u";"v";"w";"x";"y";"z";0;1;2;3;4;5;6;7;8;9},A1&"abcdefghijklmnopqrstuvwxyz1234567890")),99)
where 99 is longer than the longest string might be. If there are other legitimate starting characters, then add them to both the array constant and the string at the end.
If you might need to remove trailing spaces (char(32)), you can enclose the above in a TRIM function.

Taking substring from string between " sign // C++ Builder

I've got problem with following task. I need to load output txt data from other program to my one and search it for following string:
"zhi": 97.92716217041016,
and especially numerical value (97.92...). The "," sign is separator between other exported values.
I was trying to deal with that in c++ builder following way:
1. read file
2. load lines as strings
3. find position of zhi
4. add 6 to position - this will point on numbers
5. delete everything before new pointer
6. delete everything after 15 char
I know there have to be some easier way but I'm beginner with c++.
Can someone guide me what function I can use to find numbers between "zhi": and , ?
Use std::getline to read file as std::string types.
Use string::find to get the position of the text after "zhi":.
Use string::find to get the position of the ','.
Use string::substr to get a copy of the string between the two positions.
Remember, modifying files in the middle is difficult, especially if you have to delete or insert more characters.
The traditional method of modifying files is:
1. Copy all unchanged content from original file to new file.
2. Write changed text to new file.
3. Write remaining unchanged text to new file.
4. Close all files.