Octave: read a string from a file including blanks - octave

I want to read a file that has lines of 80 character length, containing blank spaces.
I want to have the 80 characters including the blanks in one string.
I use Data=fscanf(fid,"%80s","C") but the returned string stops at the first blank character encountered.

The anser is to use Data=fgetl(fid). This reads line by line including blanks.

Related

concern while importing/linking csv to access database

I have a csv file with delimiter as , (comma) and few of the data column of same file has comma in it .
Hence while linking / importing the file, data is getting jumbled in next column.
I have tried all possible means like skip column etc , but not getting any fruitful results.
Please let me know if this can be handled through VBA function in ms-access.
If the CSV file contains text fields that contain commas and are not surrounded by a text qualifier (usually ") then the file is malformed and cannot be parsed in a bulletproof way. That is,
1,Hello world!,1.414
2,"Goodbye, cruel world!",3.142
can be reliably parsed, but
1,Hello world!,1.414
2,Goodbye, cruel world!,3.142
cannot. However, if you have additional information about the file, e.g., that it should contain three columns
a Long Integer column,
a Short Text column, and
a Double column
then your VBA code could read the file line-by-line and split the string on commas into an array. The first array element would be the Long Integer, the last array element would be the Double value, and the remaining "columns" in between could be concatenated together to reconstruct the string.
As you can imagine, that approach could easily be confounded (e.g., if there was more than one text field that might contain commas). Therefore it is not particularly appealing.
(Also worth noting is that the CSV parser in Access has never been able to properly handle text fields that contain line breaks, but at least we can import those CSV files into Excel and then import into Access from the Excel file.)
TL;DR - If the CSV file contains unqualified text containing commas then the system that produced it is broken and should be fixed.

Weka and CSV files

I'm currently trying to import some data into weka. Currently the data is in a CSV file, and consists of a numerical ID and then some string data(Tweets). I'm getting an error where it is reading "Wrong number of values, Read 1, expected 2 Token[EOL], line 17". I'm using quotes as my enclosure characters for the String data. I understand that something(presumably an EOL character?) is causing weka to incorrectly separate some of the String data into multiple entries on the same line, but I'm not sure how to fix the EOL token problem.
My data set can be viewed here. The current data set is on Sheet 2:
https://docs.google.com/spreadsheets/d/1Yclu0t4ITFWn6itYBsVtkGalmP9BPaWFFP6U6jAeLMU/edit?usp=sharing
The text file itself may be found here:
https://drive.google.com/file/d/0B433FqC3TscQQkRxZklQclA3Z3M/view?usp=sharing
Current error is now on the 3rd line, with the same error. The only newline character there is the one at the end of the line denoting a new entry, so I'm not sure why its having issues.
In its datasets, Weka considers a newline character as an indication of the end of instance. Your line 17 is actually a multi-line tweet which confuses Weka. You can use either
a RegEx to get rid of the newline characters in every single tweet or
during downloading the tweets, clean the tweets to get rid of any newline character in them.
Unfortunately, Weka does not have a mechanism to get rid of this problem by itself (as far as I know).
EDIT
Okay, here are some other things that need to be fixed (according to your EDITS in the question):
Replace ' with \'
Replace grave accent with \grave accent
Many tweets contain quotes inside quotes. The inside double quotes (") should be replaced by \"
If you put your tweets inside double quotes, then your header should be id, "text"
Some tweets contain two consecutive double quotes, get rid of them or replace them with \".
I cannot say exactly where, because I lost trace, but I think still some tweets contain new lines in them (or at least one tweet has it still)
These are just a few things that I noticed. There might be more. Time will tell.

how I can fix this? python3.2

I'm trying to finish a program that converts text2bin and bin2text among other things, but I have a problem with the bin2text function, but only with some characters.
This is the part that is giving me problems:
def bin2text(self):
cadena2=' '
self.ventana.caja1.text()
split=[self.ventana.caja1.text()[x:x+8] for x in range(0,len(self.ventana.caja1.text()),8)]
for i in splits:
cadena2=cadena2+chr(int(i,2))
self.ventana.caja2.setText(cadena2)
I'm getting the error:
Invalid literal for int() with base 2 '100000 1.... '
on the line
cadena2=cadena2+chr(int(i,2))
(The ellipses dots aren't actually a part of the error but there's an arrow in the way in the figure)
when I try to go from binary to text, using "space" or any sign that the passing of ASCII to Bin, the number consists of six digits, I get the error. Seven or eight digit numbers work.
I need to know a how to add a 0 at the beginning of this series(0100000), to fix it
See figures below:
try this:
splits = self.ventana.caja1.text().split() #split by whitespace
for i in splits:
cadena2=cadena2+chr(int(i,2))
The problem is not the number of digits, the problem is the whitespace within the string you sent to 'int'

Looking for a vim command to insert a character on certain lines

There may or may not have been asked before, but I don't know enough about vim to be able to look. How can I add add single quotes (') 5 characters into the line and at the end of every line that begins with a (-)
An example from the file is
want quotes
here & here
v v
- essentials.help
- essentials.helpop
- essentials.list
- essentials.motd
- essentials.rules
- essentials.spawn
- groupmanager.notify.self
You could do something like:
:%s/^ -\(.*\)/ -'\1'/
Adjust the exact number of spaces you need as required.
This searches for the start of a line ^, then four spaces, a dash, and then uses a capturing group to capture all the characters to the end of the line. Then it's replaced with four spaces, a dash, a single quote, \1 is the contents of the capturing group, then a final single quote.
The leading % applies this command to all lines in the file.

iPhone: Decode characters like \U05de

I used SBJsonParser to parse a json string.
inside, instead of hebrew chars, I got a string full of chars in a form like \U05de
what would be the best way to decode these back to hebrew chars,
so i can put these on controls like UIFieldView?
Eventually I ran a loop iterating in the string for the chars \u
in the loop, when detected such a substring, i took a range of 6 characters since that index,
giving me a substring for example \u052v that need to be fixed.
on this string, i ran the method [str JSONValue], which gave me the correct char, then i simply replaced all occurrences of \u052v (for example) with the latter corrected char.