How come the pound sign '£' in Haskell is shown as '\163' instead of outputting '£'? [duplicate] - haskell

This question already has an answer here:
Haskell writes '\n' instead of a newline
(1 answer)
Closed 2 years ago.
I'm trying to write a program that writes the pound sign '£' in Haskell, but it outputs '\163' whenever I try to use it. I'm guessing that this is some alphanumeric code, but how do I get it to display what I want it to? I'm writing to the console, when calling a function that returns '£'.
Thank you.

This was solved by using putStrLn, because print and show do not allow for non-ASCII characters to be shown.

Related

Splitting a character in Linux by numbers [duplicate]

This question already has answers here:
How to extract date from filename with extenstion using shell script
(2 answers)
Closed 9 months ago.
Here I print the file,
cat testfile.txt
demo_test_file_2022-06-06
i need a output like this
demo_test_file_ 2022-06-06
please help me for splitting the line when numbers present in Linux
thanks in advance
You need to read that file line-by-line into an std::string variable, then use find_first_of to find the first digit.
Then use substr

How to calculate the length of a xterm control sequence [duplicate]

This question already has answers here:
How can I remove the ANSI escape sequences from a string in python
(8 answers)
Closed 3 years ago.
I am looking to format text before passing it to stdout/console. To do this properly I need to know how long a given section of text is after being printed to the console, which requires knowing how much characters will not be printed due to them being escape sequences.
On the web I have found multiple documentations for these sequence commands, but there seems to be no quick and easy way to find out where a given escape sequence command ends unless I was to parse them. Is there a trick/solution to getting the length of any escape sequence command without parsing?
How many characters is this \x1b[38;2;20;60;122m string \x1b[0m in console?
You can use ansifilter:
$ printf '\x1b[38;2;20;60;122mabc\x1b[0m' | ./ansifilter --no-trailing-nl | wc -c
3

Usage of '-' after pipe [duplicate]

This question already has answers here:
What's the magic of "-" (a dash) in command-line parameters?
(5 answers)
Closed 5 years ago.
I saw this line of code the other day and I didn't know exactly what is this - or when to use it. This is a simple code and from what I understood is that - takes the piped output and treats it as an argument of paste (correct me if I'am wrong)
seq $size | paste - $file
My question is when can we use this and is there another way to do the same thing?
Thanks,
This is documented in the man page for paste which says:
With no FILE, or when FILE is -, read standard input.
That is, paste expects you to give it a filename, but you can instead give it a single - instead, which paste will interpret as it should read data from stdin , your pipe in this case, instead of opening a file and read data from that file.

Print out text using one String in Python [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am learning Python by using Pycharm from Jetbrains . I am unable to pass this Question :
Print out this text using one String "The name of this ice-cream is "Sweet'n'Tasty"
My solution is:
print('The name of this ice-cream is \"Sweet\'n\'Tasty\"')
It shows the right output but the program does not accept is as a solution.
Why the seemingly right answer is not accepted, and how to satisfy given requirement?
I found this page because I ran into the exact same issue, earlier today.
In short, it's the lesson's logic being picky on syntax, in a very unclear way. You're typing the right thing for what it's asking, and you're typing something that parses with no error-- but the lesson rejects it anyway.
The long, drawn out answer.
The task is:
A backslash is used to escape a quote so it can be used in strings such as 'It\'s me' and "She said \"Hello\"". The special symbol '\n' is used to add a line break to a string.
Print out this text using one string: The name of this ice-cream is "Sweeet'n'Tasty"
And they provide to you:
dont_worry = "Don't worry about apostrophes"
print(dont_worry)
print("The name of this ice-cream is \"Sweeet\"")
print('text')
where the text in the print('text') on the last line is meant to be replaced with your answer.
The lesson seems to want to teach you that you can escape both a single quote and a double quote with a backslash. Note the double quotes on the second print instance, and the single quote on the third print instance [where they want you to type your answer]
if you replace the text in print('text') with: The name of this ice-cream is \"Sweeet'n'Tasty\"
the task fails with:
File
"/PycharmProjects/PythonIntroduction/lesson3/task8/character_escaping.py",
line 4
print('The name of this ice-cream is \"Sweeet'n'Tasty\"')
^ SyntaxError: invalid syntax
so if you add slashes to the single quotes [apostrophes in this context]
print('The name of this ice-cream is \"Sweeet\'n\'Tasty\"')
even though the text does parse correctly in the console below:
Don't worry about apostrophes
The name of this ice-cream is "Sweeet"
The name of this ice-cream is "Sweeet'n'Tasty"
The task fails and you get an infuriating error that reads:
Use backslash () to escape quotes
Even though that's what you've done.
If you try to backspace the single quotes to replace with double quotes for print('text') you get:
It's not allowed to delete answer placeholders
Now - if you move cursor [or caret] next to a quote, you get a lightbulb hint that gives you an option to:
Convert single quoted string to double-quoted string
which is what they want you to do ... but through some logic error, it takes your typed answer of
print('The name of this ice-cream is \"Sweeet\'n\'Tasty\"')
and munges it up to:
print("The name of this ice-cream is \\")
and the boundaries for the answer box text get all fouled up and wrap up to the previous line-- it looks like a bug in the lesson software itself.
SO
what you must do from the start is use your cursor to get the lighbulb hint FIRST and "Convert single quoted string to double-quoted string"
so that print('text') becomes print("text")
^^^ note the change from single to double quotes ^^^
and THEN type your correct answer of
print("The name of this ice-cream is \"Sweeet'n'Tasty\"")
This took me MUCH longer than I would have liked it to, to figure it out. As a beginner in programming and brand-new to Python, this was a huge roadblock. If I were using this in an instructor-led course they might have said "Oh, this is a bug in the software, you can see we're getting the right answer, let's skip it and move on." but for self-study, I was convinced I wasn't right, and I was overlooking something basic. It was discouraging as slamming into a brick wall. Repeatedly.
I guess the teachable moment here is:
Sometimes the textbook is wrong and you have to understand & prove it to yourself why.
You can also try using as in python if you use a single quote outside then double quotes are allowed within the String.
`print('The name of this ice-cream is "Sweet\'n\'Tasty"')`
Also for more reference, you can have a look here
I hope that helps.

python, \t works different when passed as argument (in Eclipse) [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Python: Split string with multiple delimiters
Convert django Charfield “\t” to tab
I have written a python code in Eclipse which takes delimiters as an argument. When I do
print "Hello",delimiter, "All".
This generates --> Hello \t All, whereas if I overwrite the delimiter with delimiter = '\t' within the code, I get the right output Hello All. I wonder what is the difference? I hope this not just the eclipse thing.
The problem is that what is being passed in from the command line is actually a string of length two "\\t" and not a tab character. You can do the following to your delimiter
delimiter.decode("string_escape"))
that should convert the string '\\t' into '\t'. The answer comes from a duplicate questions here

Resources