How to save a line break into a plist NSArray? - nsstring

I am trying to save an NSArray into a plist such that each element of the array is a string with line breaks.
I understand that the plist can be edited directly by hitting option +enter keys.
But I need to save the NSString with line breaks into the array so that when read back into a tableview all I get is the part of the string before line break.
So far I have tried adding /n, /r/n, /n/n
the plist looks like this:
The first element is a string with line breaks, how can I get 20,5,100 on newlines?
Thank you very much, any advise is much appreciated!

Related

Save QString in QSettings without quotes

I save some values in my .ini-file which works fine.
Now I want to save a QString in the file, which I put together inside my application.
QString s = "xwr289vjkloji9";
QSettings settings("file.ini", QSettings::Format::IniFormat);
settings.setValue("dbp", s);
Inside my file.ini it saves dbp="xwr289vjkloji9"
Basically this is right, but I need the String without quotation marks. Is there any way to remove them or should I save the String differently?
I cannot cut the first and last letter, because the quotes do not exists inside the String, they're just the String-identifier.
My only option now is to cut the quotation marks when receiving the value back from the file but I want to try it without, maybe there is a way.

Optimized way to write a series strings to a text file without quotations

I am new to Julia so sorry if this question is obvious.
I am trying to use Julia to help me run a series of finite element models, which use a text input file to give instructions to the finite element solver. Basically, I would like to use Julia to read in the base input file, edit some parameters on some lines of the file and then write it as a new file. I am getting hung up on a couple things though.
Currently, I am reading in the file like this
mdl = "fullmodelSVTV"; #name of input file
A = readlines(mdl*".inp")
This read each line from the file in as a separate string in a vector which I like because it makes it easier to edit the sections I want but it also makes things more difficult when I try to write to a new file.
I am writing the file like this.
io = open("name.inp","w")
print(io,A)
close(io)
When I try to write to a new file the output ends up look like this
Output from code
which is ["string at index 1","string at index 2","string at index 3"...].
What I would like to do is output this the exact same way is it is read in with string at each index of the vector on its own line. I would also like to remove the brackets and quotation marks from the file, as they might interfere with the finite element solver.
I think I have found a way to concatenate all of the strings at each index and separated them with a new line like shown below.
for i in 1:length(A)
conc = conc*"\n"*lines[i]
end
The issue with this is that it takes a long time to do given the size of the input files I am working with and I feel like there has to achieve my goal.
I also cannot find a way to remove the brackets or quotation marks when writing the file.
So, I'm wondering if anyone has any advice for a better way to write these text files in terms of both concatenating all of the strings from the vector when outputting as well as outputting without the brackets and quotation marks.
Thanks, any advice is appreciated.
The issue with print(io,A) is that it is printing a representation of the vector, but in fact you want to print each element of the vector. To do so, you can simply print each line in a loop:
open("name.inp", "w") do io
for line in A
println(io, line)
end
end
This avoids the overhead of string concatenation.

How to add proper spacing in my PSV file?

I have a psv file for some config for my program and it looks really bad. When I save this config from kdb it removes all the white space and it looks like this:
column1|column2|column3
somevalue1|somevalue2|somevalue3
somevalue4|somevalue5|somevalue6
and I want it to look like this when I open it with a text editor like notepad or visual studio code
column1 |column2 |column3
somevalue1 |somevalue2 |somevalue3
somevalue4 |somevalue5 |somevalue6
This psv file has 20000 rows so please don't tell me I have to do this manually.
The reason for which I need to do this spacing is because sometimes my colleagues need to open it to modify just one thing and it is much more readable with the spacing.
I work on linux and I know kdb,python and R so anything in those languages that could help me?
This is quite crude but this q function will take an existing psv file and pad it out:
pad:{m:max each count#''a:flip"|"vs/:read0 x;x 0:"|"sv/:flip m$a}
It works by taking the max string length of each column and padding the rest of the values to the same width using $. The columns are then stitched back together and saved.
Taking this example file contents:
column1|column2|column3
somevalue1|somevalue2|somevalue3
somevalue4|somevalue5|somevalue6
somevalue7|somevalue8|somevalue9
Passing through pad in an open q session:
pad `:sample.psv
Gives the result:
column1 |column2 |column3
somevalue1|somevalue2|somevalue3
somevalue4|somevalue5|somevalue6
somevalue7|somevalue8|somevalue9

Python3.6 How do I read line by line and split those lines on commas?

After spending a few hours trying to figure this out (From questions already asked and other places), I'm still stuck on it. The goal is to read from a text file (Have that working), line by line (Not working). As it stands, this is my latest attempt:
With open("Product.txt","r") as file:
for i in file:
lineRead = file.readline()
productSplit = lineRead.split(",")
productNameList.append(productSplit[0])
productCostList.append(productSplit[1])
productPriceList.append(productSplit[2])
What I am trying to do:
Read the text file line-by-line.
Split the result on commas.
Assign values at specific indexes to specific lists.
I'm not really sure how to use readline, and I couldn't understand it from the documentation, nor the other questions. I think that's where my problem is. I'd appreciate being told what I'm doing wrong. And as a side note, could I read in the whole file, split on the new line, and then split those indexes on commas?
productNameList = []
productCostList = []
productPriceList = []
With open("Product.txt","r") as file:
for line in file:
productSplit = line.split(",")
productNameList += [productSplit[0]]
productCostList += [productSplit[1]]
productPriceList += [productSplit[2]]

Delete a chosen line from a text file using ASP?

I have a loop that finds duplicate lines in a .ini file. I can happily find the duplicate lines, and write new lines to the file using FileSystemObject, however... I can't seem to find out how to delete the duplicate lines. What I want to do is delete the lines by line number as I have identified the relevant line number already.
Is there a native way to do this, or is it a case of rewriting the file minus the duplicate lines?
Any help is greatly appreciated.
Thanks.
My method of finding the duplicate entry is as follows:
Do While Not file.AtEndOfStream
intLineNumber = intLineNumber + 1
strReadLineText = file.ReadLine
If strSearchText <> "" And InStr(strReadLineText, strSearchText) > 0 Then
session("message") = "Line Exists on " + Cstr(intLineNumber)
'' # delete duplicate line...
End If
Loop
file.Close()
You can see where my comment is, is where I wish to remove the line that is found.
There are no built-in methods to do this in VBScript (or the intrinsic objects).
My vote would be to use string concatenation to accomplish this; i.e. instead of deleting lines, create a new file, line by line, and only append to the string if the line doesn't exist in the string you're building.

Resources