I am trying to make an application in AppleScript to read a list of songs in a text file and I am able to read the file fine until there is an apostrophe (') in the text.
My text file has the content of
Follow Me Down
Money For Nothing
Better When I’m Dancin’
And the code is:
set theFile to "/path/to/file"
set fileHandle to open for access theFile
set songs to the paragraphs of (read fileHandle)
close access fileHandle
display dialog songs
However AppleScript outputs Can’t make {"Follow Me Down", "Money For Nothing", "Better When I‚Äôm Dancin‚Äô"} into type string.. I know there is another error which says it cannot type the array into a string, I don't care about that since I just wanted the output of the array, what I do care about is why does an apostrophe make it output "‚Äô" instead.
If anyone could help me to fix the apostrophe changing to the characters "’", that would be great, also it would be good to know why this happens too.
Related
Trying to debug a program in Scilab, I inserted a couple
of "print" instructions to track what is going on.
At first, I used the %io(2) output "file" which, according
to the Help, stands for the console. Nothing happened.
Then I used an actual filename:
print("C:\Leszek\Xprmnt\scl\Ovsjanko\K3ScilabLog.txt", "START! \n \n \n \n GOING \n")
which does print to that file, but when the dust has settled
and I want to inspect the file what I find inside is just the last
message (just before the program crashed), even though there should
have been others before it, including the "START" etc in the quote above.
Apparently, every print command reopens the file for writing as a clean slate,
overwriting whatever was in it before. Looking into Help and online docs
I didn't find any options or parameters that I could use to change this.
What I want is, obviously, the output from all my print commands since the
beginning of the program, either on the console or in a text file.
TIA.
Just use disp("some text") or mprintf("format",var1,...,varn), both will display on the console. If you need to write in a file use fd = mopen("file.txt") then mfprint(fd,"format",var1,...,varn).
I am searching for a highly stable way to feed text (output of a program) into vim through vimserver. Assume that I have started a (g)vim session with gvim --servername vim myfile. The file myfile contains a (unique) line OUT: which marks the position where the text should be pasted. I can straight forwardly achieve this from the commandline with vim --servername vim --remote-send ':%s/OUT:/TEXT\\rOUT:/<Enter>'. I can repeatedly feed more text using the same command. Inside a C-program I can execute it with system(). However TEXT which is dynamic and arbitrary (received as a stream in the C-program) needs to be passed on the command line and hence it needs to be escaped. Furthermore using the replacement command %s vim will jump to the position where TEXT is inserted. I would like to find a way to paste large chunks of arbitrary text seamlessly in vim. An idea is to have vim read from a posix pipe with :r pipe and to write the the string from within the C-program to the pipe. Ideally the solution would be such that I can continuously edit the same file manually without noting that output is added at OUT: as long as this location is outside the visible area.
The purpose of this text feed is to create a command line based front end for scripting languages. The blocks of input is entered manually by the user in a vim buffer and is being sent to the interpreter through a pipe using vim's :! [interpreter] command. The [interpreter] can of course write the output to stdout (preceded by the original lines of input) in which case the input line is replaced by input and output (to be distinguished using some leading key characters for instance). However commands might take a long time to produce the actual output while the user might want to continue editing the file. Therefore my idea is to have [interpreter] return OUT: immediately and to append subsequent lines of output in this place as they become available using vimserver. However the output must be inserted in a way which does not disturb or corrupt the edits possibly made by the user at the same time.
EDIT
The proposed solutions seem to work.
However there seem to be at least two caveats: * if I send text two or more times this way the `` part of the commands will not take me back to the original cursor position (if I do it just once still the markers are modified which may interrupt the user editing the file manually) * if the user opens a different buffer (e.g. the online help) the commands will fail (or maybe insert the text in the present buffer)
Any ideas?
EDIT: After actually trying, this should work for you:
vim --servername vim --remote-send \
":set cpo+=C<CR>/OUT:<CR>:i<CR>HELLO<CR>WORLD<CR>.<CR>\`\`"
As far as I can see, the only caveats would be the period on a single line, which would terminate :insert instead of being inserted, and <..> sequences that might be interpreted as keypresses. Also, need to replace any newlines in the text with <CR>. However, you have no worries about regular expressions getting muddled, the input is not the command line, the amount of escaping necessary is minimal, and the jumping is compensated for with the double backticks.
Check out :help 'cpoptions', :help :insert, and :help ''.
Instead of dealing with the escaping, I would rather use lower-level functions. Use let lnum = search('^OUT:$') to locate the marker line, and call setline(lnum, [text, 'OUT:']) to insert the text and the marker line again.
SITUATION:
My instructor for my micro-controller class refuses to save sample code to a text file and instead saves it to a word document file instead. When I open up the doc file and copy/paste the code into my IDE "CodeWarrior" it causes errors upon compile time.
I am having to rewrite all the code into a text editor and then copy/paste it into my IDE.
MY UNDERSTANDING:
I was told to always save code as a text file because when you save code as a word document file it will bring in unwanted characters when your copy/pasting the code into your IDE for compiling.
MY QUESTIONS TO YOU:
1.)
Can someone explain this dilemma to me so I can understand it better? I would like to present a better case next time when I receive errors and to also know more about what is happening.
2.)
Is it possible to write a script that will show me all the characters that are being copied and pasted into a file when the code is coming from a word document vs. a text file? In otherwords is there a program that will allow me to see what is going on between copying/pasting code from a word doc file versus a txt file?
Saving source code as a Word document is just silly. If your instructor is insisting on this, chances are no matter how well-reasoned and thorough your argument, they're not going to listen. They're beyond help.
However, to answer your questions: 1) It depends on what you're pasting the thing into. Programs that copy onto the clipboard usually make the data available in several different formats, ranging from their own internal format to plain ASCII text, to maximize compatibility so that the data can be pasted into pretty much any target program. Most text editors will only accept the plan-text version, in which case no extra characters should be transferred. However if your text editor supports RTF or HTML, this may not be true. I'm not sure what CodeWarrior supports but it is certainly possible.
A workaround if this is the case: First paste into a PURE text editor like Notepad. Then copy from Notepad into CodeWarrior. This should eliminate any hidden formatting. As shoover said above, make sure double-quotes " are really double-quotes and not the fancy left- and right-specific quotes that Word sometimes uses.
Use a hex editor like XVI32 to see the raw contents of the file, including nonprinting characters. Or use a text editor with support for showing nonprinting characters (vi/vim, etc.).
I'm studying C and I've just had the same problem. When coping a piece of code from a PDF file and trying to compiling it, gcc would return a serie of errors. Reading the answer above I had an idea: "What if I converted the utf8 into ascii?". Well, I found a website that does just that (https://onlineutf8tools.com/convert-utf8-to-ascii). But instead of also converting the utf8 characters into ascii, it showed them as hexadecimals (Copying from the website to the text editor you can see it better). From there i realised that the problem were mostly the quote marks "".
I then copied the ascii "translation" into my code editor (I must add that it worked fine with Sublime, while VScode read the same utf8 code as it was in the original file, even after cp from the website) and replaced all the hex with the actual ascii characters that were needed to compile the code properly. I used the function find and replace from my editor to do it. I must say that it wasn't very fast doing it. But I believe that in some cases, if the code you're trying to copying is too long, doing it the way I've just described could be faster than rewriting the entire code.
I'm working on a programming assignment and I was wondering if somebody could help me out with this issue. This assignment says to write a program in Prolog which takes the text from an input text file and write it to an output text file. In order to get the location of the text files, the user needs to be prompted to write the path of the text files.
I have figured out how to do it, but I have one small issue that is really annoying. Here is my code:
main:-
%Ask the user for the input text file and then open the file
write('Please enter the filename you would like to read from:'),
nl,
read(X),
open(X,read,In),
%Ask the user for the output text file and then open the file
write('Please enter the filename you would to write to:'),
nl,
read(Y),
open(Y,write,Out),
%Read in characters from the input text file and then put them
%on the output text file.
tell(Out),
repeat,
get_char(In,T),
write(T),
T == end_of_file, !,
close(In),
told,
close(Out).
Let's say the text file that is going to be read says "this is a test". My issue is if I use the program to save this text and write it to another text file, it will write "this is a testend_of_file" instead.
I realize that this is happening because the loop isn't being terminated at the right time, but I'm not sure how to go about fixing the loop so "end_of_file" doesn't get accidentally written to the text file as well. Any help would be much appreciated. I feel like I've tried everything.
You first do write(T), and after that your testing for T == end_of_file, so no surprise end_of_file will be written.
Try ( T == end_of_file -> ! ; write(T), fail ),
What Prolog system are you using, BTW?
Suppose I wrote a letter in notepad and I saved it as letter.txt. Then I realized that I forgot to say one matter in that letter. So I opened letter.txt using any text editor such as Notepad, Wordpad or something. Now I inserted the letters which I want to say in this letter at the middle of the file. How does it work?
Example:
Here is a message:
" Hi, How are you. Today i want to meet you. Thank you.
It is actually stored in memory like this:
"Hi,\nHow\0are\0you.\0TodayToday\0i\0want\0to\nmeet\0you.\nThank\0you.
Now I want to add I am fine after How are you. How does it work? How is it added in the middle of the file? how are the other words not overwritten? What is the process behind it?
For small files, text editors just read the whole file in memory. When you modify the text, the text editor modifies the in-memory version. Then when you save, the text editor overwrites the original file with the new contents -- so the whole file is overwritten, and the text is written to the file as-is without any references or other tricks.