how to input single quotation mark in a text in matlab - text

trying to input the symbol ' - single quote inside a text will terminate the text. how to give the ' as input inside a text
a=';
a=';
|
Error: String is not terminated properly.
msg='asdfasdfasdf'asdfasdf';
msg='asdfasdfasdf'asdfasdf';
|
Error: Unexpected MATLAB expression.
In the first line i am trying to give single quote as input to a variable and in the next line i tried to give single quote in between. but both issues error. how can i solve this. kindly help me.

The answer can be found in many other questions by googling for two seconds... Just use double apostrophe.
msg='abdabc''abcabc';
Or alternatively:
msg=strcat('abcabc', char(39), 'abcabc');

Related

In Azure Mapping Dataflows has anyone been able to successfully change the escape character of a Source Dataset?

Has anyone tried this using the Mapping Dataflows?
Example input field is:
"This is a sentence, it contains ""double quotes"" and a comma"
The escape character is a " and the quote character is a ".
When I use a regular Copy activity this works without a problem, however
when using the same Dataset in a Mapping Dataflow it gets parsed into 2 fields instead of one. In fact changing the escape character makes no difference.
Closing this issue. I've realised that output still has the \ as the escape character so when opening the output file in Excel it appears corrupted

Multiline input prompt indentation interfering with output indentation

I have a function that prints the number of pixels found in an image and then asks the user how they would like to proceed. As long as the interpreter hasn't moved on from the function I want all the output to be indented accordingly.
One such 'sub output' (the input prompt) needs to be multiple lines. So I kick off with the 3*quote (''') followed by two spaces to create the indentation. At the end of the question 'how would you like to proceed?' I use a hard return. An extra indentation is assumed by the text editor so I remove it causing the following list of suggestions to line up flush with the input variable command. Here's how it looks:
def returnColors():
#
# lots of code that does stuff...
#
print("The source image contains", lSize, "px.")
print("")
command=input(''' What would you like to do? You can say:
get all
get unique
''')
The problem with this is that the interpreter is acknowledging the indentation that separates the function body from the function statement as actual string contents, causing the output to look like this:
The source image contains 512 px.
What would you like to do? You can say...
get all
get unique
|
The only way to avoid this is by breaking indentation in the interpreter. Although I know it works, it doesn't look very good. So what options do I have?
EDIT: Just because I have the screenshot_
One thing that you should keep in mind is that once you have start a multiline string declaration, all the text until it is closed is taken as is and syntax (ie, indentation) is no longer considered.
You can start your multiline with an explicit new line so that everything in the multiline string can be indented together in code.
IE.
command=input('''
What would you like to do? You can say:
get all
get unique
''')
would print out the prompt with a new line on top, but the formatting of the text is more explicitly shown and should appear as seen.
OR you could use the \n for each new line in the string to get it formatted more correctly and remember to use a single \ after each new line. E.g.
instead of:
''' What would you like to do? You can say:
get all
get unique
'''
Try
' What would you like to do? You can say:\
\n\
\n get all\
\n get unique\
\n'
The indent won't matter, no matter where you use \n at the beginning of new line, the input() will output the same. This is will give the same input() string:
' What would you like to do? You can say:\
\n\
\n get all\
\n get unique\
\n'

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.

StringReplace illegal character

I am trying to replace commas using a code like this:
OrigQtyC := "70,000"
StringReplace, OrigQty, %OrigQtyC%, `, , All
MsgBox, %OrigQty%
Running a script containing the code above returns the following error:
Error: The following variable name contains an illegal character: "70,000"
I guess the illegal character is the comma, although I am not able to figure out why it should be illegal.
I would like to replace the comma with blank (empty).
Neither from this nor this questions I've figured out what's wrong with my use of that command.

Can someone please explain the below code and the following query too

I did use the manual but I am unable to get all the options together to understand what the above code is actually doing.
awk -v v='"' 'BEGIN{FS=OFS=v}{gsub(",","",$2);print }' \
${SOURCE_LOCATION}/TEMP1_$file_name>${SOURCE_FILE_LOCATION}/TEMP2_$file_name
When do we have to use the curly brackets in a code after the '$' and when not to. Please explain. Any help is really appreciated.
This command would remove all the commas in the second field. The field separator being the quote character " (as specified by FS).
For example, the following string:
something "string, with, commas" something "else, here, and more"
would be transformed to:
something "string with commas" something "else, here, and more"
The significance of {} in variable names has been well explained by #Joni.
The input is read from the file ${SOURCE_LOCATION}/TEMP1_$file_name and output is redirected to ${SOURCE_LOCATION}/TEMP2_$file_name.
You must use the curly brackets syntax when a variable name is followed by something that's not part of the variable name but could be confused with it. For example, compare
hello="Hello"
echo $hello_world
with
hello="Hello"
echo ${hello}_world
The first one outputs an empty line (or the value of the shell variable hello_world, if it exists), and the second one outputs Hello_world.
In your case they are not necessary because a slash can never be a part of the variable name. Some people prefer to use the brackets to make it clear where the variable begins and where it ends even when they are not required.

Resources