I want to read a text file in Objective-C till a specified delimiter
For eg:if this is my .txt input file ,
#abc = name1$
#xyz = name2$
i want to read abc and assign it in the string variable key,and read name1 till $ and assign it to variable value
for eg:expected output
key = abc
value= name1
key = xyz
value= name2
Kindly suggest me some solution, which functions are available in objective-C, what is its syntax.
Get the -filedescriptor from the NSFileHandle, then use fdopen to retrieve a FILE *, finally use fscanf to read formatted input.
Or, read the whole file into an NSString and -enumerateLinesUsingBlock: to act on each line individually.
Related
I was expecting Null_marker to replace the blank STRING with null but, it did not work. Any suggestions, please?
tried using the --null_marker="null"
$gcloud_dir/bq load $svc_ac --max_bad_records=10 --replace --source_format=CSV --null_marker="null" --field_delimiter=',' table source
the empty stings did not get replaced with NULL
Google Cloud Support here!
After reading through the documentation, the description for the --null_marker flag states:
Specifies a string that represents a null value in a CSV file. For example, if you specify "\N", BigQuery interprets "\N" as a null value when loading a CSV file. The default value is the empty string.
Therefore setting null_marker=null will not replace empty strings with NULL, it will only treat 'null' as a null value. At this point you should either:
Replace empty strings before uploading the CSV file.
Once you have uploaded the CSV file make a query using the replace function.
I am currently trying to parse file with contents something like this using sscanf:
param1 = value1
...
param5=value5
...
paramn = valuen
I need to extract values by param name.
For example:
sscanf((char*)rtext, "param5=%s", label)
I am trying to get "value5" into string variable "label".
This example returns 0 coincidences. I have tried various specificators with no luck. Looks like this not working because there is another symbols including new line before "param5". How to tell sscanf to skip this until "param5" will be found? Thank you.
Read file line by line until you will get the successful scan.
After compressing my data, I have several string variables with storage type str4 or str1 and format %9s. I would like to revert them all to the default display format, which help dformat reports should be %#s for str#. Is there a quick way to do this?
This is the structure of my best guess:
ds, has(type string)
foreach v of varlist `r(varlist)' {
format `v'
}
This does not work because, instead of reformatting to the default value with this command, the format function just displays the format.
A reproducible example:
clear
input str50 mystr
"b"
"a"
end
compress
format myst
This is the situation I was confronted with. I am not sure if it applies beyond strL formatted variables. (Roberto suspects that it does not; see comments.)
Addendum. My goal here was to make browse-ing my data easier. It seems that format is respected in the browser (truncating to length of one for %1s, say), while it is overridden by the actual length of the string when printing to the console.
I am surprised that you seem surprised, as with your syntax the format command (not function) does indeed just display the format, as is documented. Incidentally, you don't need a loop to do that as format will take a varlist as argument:
. clear
. set obs 1
obs was 0, now 1
. foreach t in a b c {
2. gen `t' = "`t'"
3. }
. format a b c
variable name display format
-----------------------------
a %9s
b %9s
c %9s
-----------------------------
Joshing apart, I think you need just one line here, which is something like
. format a b c %1s
or
. format a b c %-1s
to signal which justification. Stata doesn't truncate displayed strings just because they don't match the string display format; it might well truncate strings because there isn't space to show them, but (I'm naturally open to counter-examples) the above display formats for variables will do well for most purposes.
EDIT: The following device may help.
gen length = 0
ds, has(type string)
quietly foreach v in `r(varlist)' {
replace length = length(`v')
su length, meanonly
format `v' %`r(max)'s
}
drop length
How can I get an input from user in Lua (like scanf in C)?
For example, the program ask user his name, then he writes his name, then the program will output his name.
Use io.read() Beware that the function can be customised with different parameters. Here are some examples.
s = io.read("*n") -- read a number
s = io.read("*l") -- read a line (default when no parameter is given)
s = io.read("*a") -- read the complete stdin
s = io.read(7) -- read 7 characters from stdin
x,y = io.read(7,12) -- read 7 and 12 characters from stdin and assign them to x and y
a,b = io.read("*n","*n") -- read two numbers and assign them to a and b
The simplest input can be retrieved using io.read(). This will read a single line from the standard input (usually the keyboard, but can be redirected e.g. from file).
You can use it like this:
io.write('Hello, what is your name? ')
local name = io.read()
io.write('Nice to meet you, ', name, '!\n')
io.read() is just a shortcut for io.input():read(), similarly io.write() is a shortcut to io.output():write(). See the API for read() here.
Notice that io.write() will not auto-terminate your line like print() does.
I have written a simple program where to read the first 4 characters and get the integer of it and read those many character and write xxxx after it . Although the program is working the only issues instead of inserting the character , its replacing.
file = open('C:/40_60.txt','r+')
i=0
while 1:
char = int(file.read(4))
if not char: break
print file.read(char)
file.write('xxxx')
print 'done'
file.close()
I am having issue with writing data .
considering this is my sample data
00146456135451354500107589030015001555854640020
and expected output is
001464561354513545xxxx00107589030015001555854640020
but actually my above program is giving me this output
001464561354513545xxxx7589030015001555854640020
ie. xxxx overwrites 0010.
Please suggest.
Files do not support an "insert"-operation. To get the effect you want, you need to rewrite the whole file. In your case, open a new file for writing; output everything you read and in addition, output your 'xxxx'.