-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to format a string? #138
Comments
Hi,
Take a look at the sprintf/sprinti functions:
http://ncl.ucar.edu/Document/Functions/Built-in/sprintf.shtml
http://ncl.ucar.edu/Document/Functions/Built-in/sprinti.shtml
Rick
…On Sat, Jun 27, 2020 at 2:27 AM QingQing Tong ***@***.***> wrote:
Hi!
How to format a string?Just like a shell script:
e.g. printf "%-10s" "abc"
Can NCL format the output string?
tks.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#138>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADLWOXUFTA7WTJVE2GZMQF3RYWUNLANCNFSM4OJ5U3GA>
.
|
These two functions are applicable to float and integer respectively, strings cannot be used. |
NCL does not provide direct support for type "s" format strings. NCL provides only printf support for numeric format types. Here is a workaround that uses a sub shell for direct access to the printf command. This is okay for small data scenarios, but not for mass data processing because it is quite inefficient. This is more complicated than you might think, because of several quirks in NCL string handling.
Result:
|
NCL procedures |
Otherwise, you can do a lot with NCL's string function library and small amounts of custom NCL code. |
Thanks for your answer, I finally solved my problem with the shell. ncl 0> str=tostring(systemfunc("printf '%-15s\n' abc")) Variable: str Variable: str |
Hi!
How to format a string?Just like a shell script:
e.g. printf "%-10s" "abc"
Can NCL format the output string?
tks.
The text was updated successfully, but these errors were encountered: