For my Job I am currently working with the programming language PROGRESS. To format numbers etc. we are using the simple STRING() function. Now the following problem appeared while developing:
If I have a number like 13 and print it using STRING(13, "Z99") I get " 13"
but if I print it using STRING(13, ">99") I still get " 13".
The problem is the blank space. From the Progress documentation it should be possible to erase the blank spaces
=>Progress Documentation
As it is defined in the Progress documentation "Z" replaces not available digits with a blank but ">" suppresses the output of the missing digit.
Currently the best solution we have is to use TRIM() around the STRING() function. But as more code goes by I can't stop thinking that this should be possible without the TRIM function.
Or am I misunderstanding the progress documentation?
Thank you guys in advance.
Version: Open Edge 12.2.8
Z and > change the behavior of any leading non-format symbol. See:
message quoter( string( 13, '$>>9' ) ).
message quoter( string( 13, '$ZZ9' ) ).
Which will produce output:
" $13"
"$ 13"
Neither of which helps you. The formats are suited for producing fixed width font tabular output.
If you do not need any formatting at all, which is unlikely as soon as your numbers are more than three or so digits, you can use string without a format:
message quoter( string( 13 ) ).
Which produces:
"13"
The quoter function has been used in all the above examples to highlight where the spaces are.
I agree that the documentation on the topic is, at best, confusing.
">" has always replaced missing digits with a SPACE. I can see how the documentation saying that it uses a "blank" is pretty confusing. I suppose that they mean to say "a blank space" or something like that.
Personally I've never actually used "Z". I've looked at it a few times over the years, tested it, and wondered what is supposedly different from ">" since I've not been able to determine that there is a difference. Maybe I should have reported a bug 30 or so years ago? Anyhow, I've never found a use for it.
To avoid TRIM use STRING() or SUBSTITUTE() like so:
display
"[" + string( 13, ">>9" ) + "]" skip
"[" + string( 13, "ZZ9" ) + "]" skip
"[" + string( 13 ) + "]" skip
"[" + substitute( "The number &1 without extra padding", 13 ) + "]" skip
.
That will result in "export format" being used for the conversion. In other words all significant digits but no commas (or "." if you are using euro format). I like SUBSTITUTE() because it behaves well with "unknown" values and in a lot of cases where you don't want padding you are probably building a parameterized string anyway.
Related
Am trying to trim a string which has multi-line whitespace and also a single-whitespace ... I want to only remove the multi-line whitespace which varies in different length ex. " ", " ",
Can anyone please help me on this and also thank you in advance
I tried trim, replaceALL method with REG(\s) pattern but they are not giving the results in want
Line breaks are encoded by special characters that are different to a regular space. Usually, they are represented by "\n", whereas a whitespace is just " ".
So for your usecase, a command like
modifiedString = originalString.replace("\n","")
will do the trick. It replaces all newlines by a 0-length string, thus removing it.
If you want to dive deep into the topic, it will also be interesting to look into the differences of "\r" and "\n".
I have started using pylatex four days ago to automate report generation (I have no earlier experience in latex as well). The text that I want to enter in the latex report has been generated by an online server and stored in my file as a text file. In the text file, there exist places with more than one simultaneous space for proper formatting and aligning (Protein Sequence Alignment). Hence, while simply trying to use .append, pylatex seems to ignore all the extra spaces on its own. I searched the internet with various relevant terms, but could not find any answer for pylatex. I did find some latex answers, exploring which I tried to incorporate pylatex's NoEscape and explicitly replacing " " (double spaces) with " \space ", it seems to work for some lines as expected, but not for others (maybe some of the places have \ (or some other special characters for latex) which are expected to be meaningful but could not understand what it actually means since it does not even exist (for example \clo). Can someone please suggest a method where I can simply allow the simultaneous existence of the spaces, which is also visible in the final document without the need to think about the existence of a possible special character that needs to be escaped. The following code snippets that I used might be of use to answer/understand my query.
i = 0
with doc.create(Subsection('Details')):
with open(whatcheck_detail, 'r') as fh:
lines = fh.read().split("#")[1:]
for line in lines:
i += 1
line = line.replace(" ", " \space ").replace("#", "\#") + "\n"
if "Note:" in line:
print(i)
# doc.append(TextColor(line))
doc.append(NoEscape(line))
elif "Warning:" in line:
print(i)
# line = "\color{blue} " + line
doc.append(NoEscape(line))
# doc.append(TextColor("blue", line))
elif "Error:" in line:
print(i)
# line = "\color{red} " + line
doc.append(NoEscape(line))
# doc.append(TextColor("red", line))
And the following is the screenshot of the last part of the error report.
Error Description upon running the above script.
Following are the images of what is happening by using the simple pylatex code doc.append(TextColor("color", line)), and what is actually in the text file (which is how I want it to be on PDF generated by latex/pylatex).
What is happening to the text in the output file.
What is in the text file, or how do I want it.
Thank you!
Before you go marking this as a duplicate hear me out
My question;
A: has different requirements than all the others (which are basically "whats an escape character?") Including: not having to use an external file to enter in parameters to functions
B: questions the existence of this mess rather than accepting 'no' or 'its complicated' as the answer
C: understands that there are escape characters that already exist and ways to work around that
D: comes from a different skill level and isn't a 2-7 years old question
E: requires the use of quotes rather than something like [ because quotes are the only thing that works with spaced strings
Also before ya'll say I didn't try stuff
I read these (all of it including comments and such):
Batch character escaping
http://www.robvanderwoude.com/escapechars.php
https://blogs.msdn.microsoft.com/oldnewthing/20091029-00/?p=16213
using batch echo with special characters
Escape angle brackets in a Windows command prompt
Pass, escape and recognize Special Character in Windows Batch File
I didn't understand that all fully, because to fully understand all that I'd have to be much better at batch but here is what I gleaned:
So I understand theres a whole table of escape sequences, that ^ is the most used one, that you can use Delayed Expansion to do this task so that the characters don't get parsed immediately, just 'expanded' at runtime, but then that the Enable Delayed expansion thing doesn't always work because with pipe characters, the other files/things being piped to/from don't inherit the expansion status so
A: you have to enable it there too
B: that forces you to use that expansion
C: it requires multiple escape characters for each parsing pass of the CLI which apparently is hard to determine and ugly to look at.
This all seems rather ridiculous, why wasn't there some sort of creation to set a string of odd inputs to literal rather than process the characters. Why wasn't it just a simple flag upon some super duper special character (think alt character) that would almost never appear unless you set the font to wingdings. Why does each parsing pass of pipe characters remove the escape characters? That just makes everything insane because the user now has to know how many times that string is used. Why hasn't a tool been developed to auto scan through odd inputs and auto escape them? We have a table of the rules, is it really that hard? Has it been done already? What would it require that's 'hard'?
Down the rabbit hole we go
How did I get here you ask? Well it all started when I made a simple trimming function and happened upon one of the biggest problems in batch, escaping characters when receiving inputs. The problem is alot of my inputs to my trimming function had quotes. Quotes are escaped by using "" in place of " so something like
::SETUP
::parenthesis is just to deliniate where it goes, it isn't
::actually in
::the code
set "var=(stuff goes here)"
call :TrimFunc "%var%",var
:TrimFunc
::the + are just to display the spacing otherwise I can't tell
echo beginning param1 is +%~1+
::code goes here for func
gotoEOF
::END SETUP
::NOTE the + characters aren't part of the actual value, just the
::display when I run this function
set "var=""a"""
::got +"a"+
will work but
set "var="a "
::got +"a+
::expected +"a +
set "var="a ""
::got +"a+
::expected +"a "+
set "var="a " "
::got +"a+
::expected +"a " +
set "var="a"
::got +"a",var+
::expected +"a+
will not work as expected. oddly,
set "var="a""
::got +"a"+
seemes to work despite not being escaped fully. Adding any spaces seems to disrupt this edge case.
Oddly enough I've tried doing:
set 'var="a"'
::got ++
::expected +"a"+
But I have no idea what changing ' to " actually does when its the one that contains the argument (not the ones that are supposed to be literal).
To see what would happen and
What I want:
Surely there must be some sort of universal escape character thing such that I can do this (assume the special character was *)
set *var=""something " "" " """*
call :TrimFunc "%var%",var
echo +%~1+
would net me
+""something " "" " """+
with no problems. In fact, why can't I have some universal escape character that can just be used to take in all the other characters inside it literally instead of the command line trying to process them? Perhaps I'm thinking about this wrong but this seems to be a recurring problem with weird inputs all over. I just want my vairbales, pipes and strings and all that to just STAY LITERAL WHEN THEY'RE SUPPOSED TO. I just want a way to have any input and not have any weird output, it should just treat everything literally untill I want it not to because it was enclosed by the mystical super special character that I just invented in my mind.
::noob rant
I don't see why this was never a thing. Whats preventing the makers of this highly useful language from simply creating a flag and some character that is never used to be the supremo escape character. Why do we need like 10 different ways of escaping characters? I should be able to programatically escape inputs if necessary, it should NEVER be the users job to escape their inputs, thats absolutely ridiculous and probably a violation of every good coding standard in existence
::END noob rant
Anyways. I'd be happy to be enlightened as to why the above is or isn't a thing. I just want to be able to use quotes IN A STRING (kinda important) And I can't comprehend why its not as simple as having one giant "treat these things as literals" flag that ALWAYS JUST WORKS(tm).
By the way, In case you're wondering why my function takes in the name of the variable it's writing to, I couldn't figure out how to get labels inside labels working without using delayed expansion. Using that means the variable I'm making is local not global so I use the name of the global variable to basically set it (using it's name) to the local value on return like this:
endlocal & set "%~2=%String%"
Feel free to yell at me on various things because I am 99% certain I'm doing something horribly syntactically wrong, have some bad misunderstandings or am simply way to naive to truly understand the complexity of this problem but to me it seems amazingly superfluous.
Why can't the last quote be used like the special character it is but any preceeding ones are taken literally (maybe depending upon a flag)
for example
set "var="a ""
why doesn't the ending two quotes act specially and the ones in between act literally? Can the CLI not tell where the line ends? Can it not tell the difference between the first and last quotes and the ones in between? This seems simple to implement to me.
As long as I can echo things properly and save their literal value from parameter to variable I'm happy.
Firstly, I'm don't really understand why you will want to use set "var=something" instead of set var=something, it doesn't seems to have difference.
Secondly, hope that helps, which I have (recently? IDK.) invented a method to deal with the annoying quotes. Hope this batch inspires or helps you to do sth similar.
#echo off
title check for length of string
color de
mode con: cols=90 lines=25
goto t
:t
set str=error
set /p str=Please enter four characters:
set len=0
goto sl
:sl
call set this=%%str:~%len%%%
if not "%this%" == "" (set /a len+=1 & rem debug" == "" (set /a len+=1
goto sl)
if not "%len%" == "4" (set n= not) else (set n=)
echo This is%n% a four character string.
pause >nul
exit
Which in your case:
if not "%var%" == "" (call :TrimFunc "%var%",var & rem debug" == "" (call :TrimFunc "%var%,var)
)
Hope that helps. Add oil~ (My computer doesn't support delayexpansion with unknown reason. Therefore, most of the codes are a bit clumsy.)
P.S.: If you are simply removing text and not replacing text, why not use set var=%var:string=%? If the string required is a variable too, then you can try this: call set var=%%var:%string%=%%
I'm trying to save some time generating a lot of reports on Excel with a program from Stata using the putexcel command.
It has worked perfectly. However, I'm encountering a problem when mixing 3 formulas in which one includes quotation marks to denote a space " ".
To be more specific, this is the code I'm using:
putexcel B2=formula("IF((VLOOKUP(A2;HI!$1:$1048576;2;));" ";VLOOKUPA2;HI!$1:$1048576;2;))") using "`archivo'", modify sheet("DEFGGF")
The problem here is that it works in Excel, but instead of the space enclosed in " " I'm getting a 0 since it doesn't read the quotation marks.
I have tried enclosing the "" in several other ways, like
'""`
or
"'"'`"`"
but they don't work.
I would post this as a comment, but I never am able to get the backtick (`) character to display properly in a comment.
I think your code should look like
putexcel B2=formula(`"IF((VLOOKUP(...));" ";VLOOKUP(...))"') using ...
but I admit to not having tested this solution. But the general principles involved are explained in the output of the Stata command help quotes##double.
Facing conflict between endeca searchable character & phrase search.
I have a word sequence for eg. hello "world. "(Double quote) is needed here.
1) Phrasing " (double qoutes special character) is enabled for search by putting it into pipeline file Project_name.search_chars.xml.
2) If I remove " from Project_name.search_chars.xml , phrasing is working properly but I am not able to search the term containing " (quotes special character in it.)
I have also tried some escape characters -
1) "hello ""world"
2) "hello \"world"
3) "hello """world"
Nothing seems working here for me.
Can anyone suggest any configuration solution for this.
If I understand your question you want to be able to search for " but not mess up the phrase functionality which under the hood creates quoted strings.
A possible work around is to perform substitution when loading the data into endeca as well as during search.
Replace the " character in your data set with something that is not currently used (a ~ is a likely choice) and make that character searchable. Next have some pre-process code replace any incoming " characters with the selected substitution so that endeca knows how to process it.
Once this is done phrase will continue to behave as expected.
We have successfully implemented this type of solution with the dash character.