How to overcome the issue relating this replaces.
I need to replace " snn" with "" & " sss" & "" in myHtml.
it will replace all " snn" with " sss". but it will not work in the begin of a line(newline, \n).
Let's assume we have the following data
the man stands on the floor
The man etc
in field 1. We can replace any occurrence of the or The or space & the or linefeed & the with an using the following syntax
on mouseUp
put word 1 to -1 of replaceText(space & fld 1,"[\n ][tT]he "," an ")
end mouseUp
Note the extra preceding space, which is removed again using word 1 to -1.
Unfortunately, this syntax replaces linefeeds with spaces. Id on't know if you want this. If not, I'd suggest using two lines, one for space and one for linefeed.
on mouseUp
put replaceText(space & fld 1,"[\n]([tT]he) ",cr & "an ") into myTempVar
put word 1 to -1 of replaceText(myTempVar,"[ ]([tT]he) "," an ")
end mouseUp
It seems a little strange to me to always replace "the" with "an" but it does what you're asking for.
Related
How to print a triangle coordinates (1,2) (3,4) (5,6) using puts? I am getting errors for the quotes.
puts "triangle just added is" "( " $ax "," $ay ") " "( " $bx "," $by ") " "( " $cx "," $cy ") "
puts takes one argument (A string to write to standard output) or two (A channel to write to and the string). Well, and the optional -nonewline option, so really 2 or 3 arguments. You're giving it a lot more than that, hence errors.
Like many scripting languages, tcl will expand variables inside double-quoted strings:
puts "triangle just added is ($ax,$ay) ($bx,$by) ($cx,$cy)"
The problem relates to a macro I'm trying to implement in Excel, specifically the shell function in the code. What the code does is that it executes chrome.exe opening a PDF file in a specific page of the document, the code is not mine it is from this post:
(Open a PDF from Excel with VBA in Google Chrome on a specific page)
and this is where I have the problem:
Dim arch As String
arch = "file:///C:\Users\user\Downloads\Trabajo.pdf#page=6"
If Not chromePath = "" Then
Shell ("""C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"" ""arch""")
End If
what i really need it to do is that the shell function opens chrome.exe and go to the path that is stored in the variable arch.
in the code that was posted it works this way:
Shell ("""C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"" ""file:///C:\Users\user\Downloads\Trabajo.pdf#page=6""")
I turned the PDF path into a variable since it will change on each PC I deliver the folder containing the excel document and the PDF
i have already managed how to get the PDF path to be read an put into the variable arch.
I feel a bit embarrassed because this might be a really silly question. Thank you very much in advance.
Surrounding your variable within quotes turns it into a string literal instead. You can tell just by looking at it within half a second that your variable won't work, because you aren't even concatenating the variable with the string literal (such as "MyString" & MyVar).
Also, you do not need to enclose your Shell argument within parenthesis since you are not using it to return a value, doing so is generally not good practice in VBA.
Anyways, there are a couple of methods I will show you here. First would be your style of surrounding with multiple double-quotes:
Shell """C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"" " & """" & arch & """"
Notice I had to combine the variable to the string with &.
And the easier-to-read using the Chr$() function:
Shell Chr$(34) & "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe " & _
Chr$(34) & arch & Chr$(34)
Chr$(34) is the character code for a double-quote character. This can make it easier to surround strings that contain actual double-quote characters within them.
Something to remember when using double-quotes:
A single " will open or close a string literal
Double "" will represent an 'Empty' string (x = "")
Now within a string literal, any quotes you want to be part of the string needs to be escaped with another double-quotation character.
Let's look closer at point # 3
MsgBox """This is a string"""
' ^^ ^ ^
' ||_ | |_ This closes (terminates) the string literal
' | | |
' | | |_This one is acting as an escape to the next "
' | |
' | |_This is escaping the next character
' |
' |_This is the start of the string literal
This can be validated because you would be able to change the above string by adding a space after the first " and before the last, such as:
MsgBox " ""This is a string"" "
While this wouldn't work without giving you a syntax error:
MsgBox "" "This is a string" ""
This is because the first opens the string the 2nd is the escape character. But it's escaping nothing but a space (same in reverse is true for the end).
Then you get to using 4 """", as with & """" & arch & """"
& """" & arch & """"
' ^^ ^
' || |_ Ends the string
' ||
' ||_ Escapes the next "
' |
' |_ Starts the string
Now you can visually see why it takes 4 " just to put a single " into a string literal by itself.
I have this line:
\\Server1\A Share & Test & Check M
I want this output:
\\Server1\A Share & Test & Check
It should end with a character and not spaces (\\Server1\A Share & Test & Check)
I tried this:
sed -i "s/[ *\t[a-z]]*$//I" shares.txt
It removes the last letter but not the spaces.
The regex you are after is \s*[a-z]*$
sed -i "s/\s*[a-z]*$//I" shares.txt
\s is for any white space character
try this
echo "\\Server1\A Share & Test & Check M" | sed 's/[\tA-Za-z]*$//g'
output:
echo "\\Server1\A Share & Test & Check
Octave adds spaces with strcat
In Octave I run these commands:
strcat ("hel", " ", "lo")
I get this result:
ans = hello
Instead of what I expected:
ans = hel lo
strcat to me sounds like "concatenate strings". A space is a valid character, so adding a space should be OK. Matlab has the same behaviour, so it's probably intended.
I find it counter intuitive. Does this behavior makes sense?
Hmm. It works how it is defined:
"strcat removes trailing white space in the arguments (except within cell arrays), while cstrcat leaves white space untouched. "
From http://www.gnu.org/software/octave/doc/interpreter/Concatenating-Strings.html
So the question could be: Should this behaviour be changed.
strcat takes the input parameters and trims the trailing spaces, but not the leading spaces. if you pass a parameter as one or more spaces, they are collapsed to blank string.
That behavior is a manifestation of how "cellstr" works where spaces at the end are removed.
Work around 1
If you put the space up against the 'lo', it is a leading space and not removed.
strcat ("hel", " lo")
ans = hel lo
Work around 2
use cstrcat instead:
cstrcat("hel", " ", "lo")
ans = hel lo
Work around 3
Use sprintf, can be faster than strcat.
sprintf("%s%s%s\n", "hel", " ", "lo")
ans = hel lo
I have the following simple line to print a new line to a log file:
Print #fileNumber, vbNewLine
However, this results in 2 newlines instead of one. My code does not have any other vbNewLines or anything that would print newlines.
If I do not have this print line, then I print no newlines, so this means this line is printing 2 newlines.
Does anyone have any ideas why?
Just tested this, and Print always adds a linebreak.
So simply using Print #fileNumber, will result in 1 blank line.
The problem is that Print already prints on a new line, so when you add vbnewline you're getting 2 lines.