How do I include superscripts in NSString? - nsstring

Is there any way I can include a superscript with NSString? For example, I want to write square feet, like this: foot2.

In this particular case, there is in fact a single Unicode character that represents a small "2" written above the line. It is U+00B2 (Superscript Two).
You should be able to do something like:
NSString *aString = [NSString stringWithUTF8String:"foot\u00b2"];

Related

How to add a dollar sign to a float input in Python?

The program is simple and I'm still learning the basics, but I can't figure out how to put a $ (dollar sign) to a float input.
print("What is your name?")
fisrt_name: input()
#How can a $ appear after the user type a number?
print('How much would you like to give?')
amt1 = float(input())
I already tried:
amt1_dollar = "${:.2f}".format(amt1)
print(amt1_dollar)
But the output shows two numbers, the number the user typed and the print with a dollar sign.
How can I do to appear only the number with the dollar sign?
Image of the output
Im sorry if the question is too stupid.... and thank you. :)
Create a new string, convert your float to string and add "$" symbol before it.
You should add your program language in tags.
You should use ``` to mark your code.
The "first_name" variable is not matter for this question, just delete it.
Think simple and clean code

Optimized way to write a series strings to a text file without quotations

I am new to Julia so sorry if this question is obvious.
I am trying to use Julia to help me run a series of finite element models, which use a text input file to give instructions to the finite element solver. Basically, I would like to use Julia to read in the base input file, edit some parameters on some lines of the file and then write it as a new file. I am getting hung up on a couple things though.
Currently, I am reading in the file like this
mdl = "fullmodelSVTV"; #name of input file
A = readlines(mdl*".inp")
This read each line from the file in as a separate string in a vector which I like because it makes it easier to edit the sections I want but it also makes things more difficult when I try to write to a new file.
I am writing the file like this.
io = open("name.inp","w")
print(io,A)
close(io)
When I try to write to a new file the output ends up look like this
Output from code
which is ["string at index 1","string at index 2","string at index 3"...].
What I would like to do is output this the exact same way is it is read in with string at each index of the vector on its own line. I would also like to remove the brackets and quotation marks from the file, as they might interfere with the finite element solver.
I think I have found a way to concatenate all of the strings at each index and separated them with a new line like shown below.
for i in 1:length(A)
conc = conc*"\n"*lines[i]
end
The issue with this is that it takes a long time to do given the size of the input files I am working with and I feel like there has to achieve my goal.
I also cannot find a way to remove the brackets or quotation marks when writing the file.
So, I'm wondering if anyone has any advice for a better way to write these text files in terms of both concatenating all of the strings from the vector when outputting as well as outputting without the brackets and quotation marks.
Thanks, any advice is appreciated.
The issue with print(io,A) is that it is printing a representation of the vector, but in fact you want to print each element of the vector. To do so, you can simply print each line in a loop:
open("name.inp", "w") do io
for line in A
println(io, line)
end
end
This avoids the overhead of string concatenation.

Data annotation for Salutation

How can I add Data Annotation for Salutation?
A salutation must begin with Dear Sir or Madam, Mr, Mrs, Dr in lower or uppercase?
I tried the following but it not working for me:
[RegularExpression(#"^(Dr|Mrs?|Ms)\. [A-Za-z] ([A - Za - z] (\s|\.|_)?)+[a-zA-Z]*$", ErrorMessage = "Greeting must begin with Mr., Mrs., Ms., or Dr")]
Use something like this: ^(Mr|Mrs|Ms|Dr)\. [\p{L} '-]+$. The assumption is that a surname can contain letters, not necessarily basic Latin (\p{L}), spaces in strict sense, apostrophes and hyphens. I did not add underscores. In the future you will probably need to extend this set.
This regular expression assumes that the salutation is all that is fed to to regular expression (i.e., that only salutation is subject to data annotation). If you check the whole letter, replace the final $ with an \n (newline); and if there can be an address before the salutation, replace the initial ^ with (?:^|\n). These newlines make sure that the salutation occupies a separate string. Do not use multiline option in this case.
Is the letter is user input, allow for extra spaces: ^\s*(Mr|Mrs|Ms|Dr)\.[ ]+[\p{L} '-]+$.
Also, the full stop after the title can be missing, so: ^\s*(Mr|Mrs|Ms|Dr)\.? [ ]+[\p{L} '-]+$.
You may want to add an optional final comma: ^\s*(Mr|Mrs|Ms|Dr)\.?[ ]+[\p{L} '-]+,?\s*$.
Possible titles are also numerous, like Prof. or military ranks.

How to extract a substring from main string starting from valid uuid using lua

I have a main string as below
"/tmp/xjtscpdownload/7eb17cc6-b3c9-4ebd-945b-c0e0656a33f0/output/9999.317528060546245771146821638997525068657/"
From the main string i need to extract a substring starting from the uuid part
"/7eb17cc6-b3c9-4ebd-945b-c0e0656a33f0/output/9999.317528060546245771146821638997525068657/"
I tried
string.match("/tmp/xjtscpdownload/7eb17cc6-b3c9-4ebd-945b-c0e0656a33f0/output/9999.317528060546245771146821638997525068657/", "/[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}/(.)/(.)/$"
But noluck.
if you want to obtain
"/7eb17cc6-b3c9-4ebd-945b-c0e0656a33f0/output/9999.317528060546245771146821638997525068657/"
from
"/tmp/xjtscpdownload/7eb17cc6-b3c9-4ebd-945b-c0e0656a33f0/output/9999.317528060546245771146821638997525068657/"
or let's say 7eb17cc6-b3c9-4ebd-945b-c0e0656a33f0, output and 9999.317528060546245771146821638997525068657 as this is what your pattern attempt suggests. Otherwise leave out the parenthesis in the following solution.
You can use a pattern like this:
local text = "/tmp/xjtscpdownload/7eb17cc6-b3c9-4ebd-945b-c0e0656a33f0/output/9999.317528060546245771146821638997525068657/"
print(text:match("/([%x%-]+)/([^/]+)/([^/]+)"))
"/([^/]+)/" captures at least one non-slash-character between two slashs.
On your attempt:
You cannot give counts like {4} in a string pattern.
You have to escape - with % as it is a magic character.
(.) would only capture a single character.
Please read the Lua manual to find out what you did wrong and how to use string patterns properly.
Try also the code
s="/tmp/xjtscpdownload/7eb17cc6-b3c9-4ebd-945b-c0e0656a33f0/output/9999.317528060546245771146821638997525068657/"
print(s:match("/.-/.-(/.+)$"))
It skips the first two "fields" by using a non-greedy match.

expression() command in R with semicolons

In the output of the following code,
curve((1+exp(-1*x))^-1,
xlim=c(-10,10),ylim=c(0,1),
main="Logistic function",xlab=expression ("x"[t-d]),
ylab=expression ("G"("x"[t-d],gamma,c)))
In the y-axis label, how to place a semi-colon in between immediately before the gamma instead of a comma?
In this case you just need to think of the semicolon as text rather than a special character you can do
ylab=expression ("G"("x"[t-d]~";"~gamma,c))
or you can use * rather than ~ if you want less space.

Resources