I need to build a string which contains Alt Codes, specifically Alt-16 (Arrow symbol). I have a line of text (aka a string). I append a Carriage return, then want an ARROW symbol and the new line of text. This line will then be passed to PPT. If I manually go into PPT, into a text box, I can hit Alt+16, and get the arrow symbol. This is what I programatically want to do.
Alt symbols found here.
Here is what I am trying, but it gives me a totally different symbol.
line := line + #13 + Chr(VK_MENU) + #16 + NewLine;
How do I build a string with ALT Codes as part of the string?
Not that those characters are not called Alt-codes or Alt-characters. The Alt-codes are just a way to type some special character, but they can't be used as such in a string.
You can just type in that character using the Alt-code, or copy it from the alt codes website. You can use the character as-is in the string. The code below would work fine:
// Show it
ShowMessage('►');
// Or use it in your string:
line := line + #13 + '►' + NewLine;
Related
I am using an Excel macro to call up UltraEdit in order to execute a script on some files.
In the Excel macro I write the path that I want the new file to be saved in by the UltraEdit script. Up until this point all work and if I do a write of the value I read in the temporary file I see that I have the correct path.
But when I use the saveAs("^c") the file does not get saved to the path I specified, but instead gets saved to the current directory.
If I use the following code it saves the file properly. But I don't want to hard code the path:
var sPath="H:\\IPEX\\DataFiles\\IPEX_Originals_Cleaned_Files\\"
+ sTransSet
+"_"
+ sDocNum
+ "_"
+ now.getFullYear()
+ month
+ day
+ "-"
+ hours
+ minutes
+ seconds
+ ".txt";
UltraEdit.saveAs(sPath);
This is the code I am trying to fix:
UltraEdit.selectClipboard(1); // switch to user clipboard #1
var sPath=asParameterList[0]
+ sTransSet
+"_"
+ sDocNum
+ "_"
+ now.getFullYear()
+ month
+ day
+ "-"
+ hours
+ minutes
+ seconds
+ ".txt";
UltraEdit.clipboardContent=sPath;
UltraEdit.outputWindow.write("sPath Value After assign= "+sPath);
UltraEdit.saveAs("^c");
The write command shows me the following:
sPath Value After assign=
H:\\IPEX\\DataFiles\\IPEX_Originals_Cleaned_Files\\856_IPEX-155630-2_20190607-152606.txt
Instead of saving the file to directory
H:\\IPEX\\DataFiles\\IPEX_Originals_Cleaned_Files\\
it saves the file to directory
H:\IPEX\DataFiles\Boomi_IPEX_Files
which is the directory of the original file.
I agree with Alexander Pavlov and his analysis of the cause of the issue. The full qualified file name in clipboard is invalid because of having leading newline characters.
And the full qualified file name string contains additionally \\ instead of just \ as directory separator. \\ within a file path is no problem for Windows file system kernel functions in comparison to the newline character which is an invalid character for a file name or path according to Microsoft's documentation Naming Files, Paths, and Namespaces. But the full qualified file name should be nevertheless 100% correct.
These issues should be best fixed in Visual Basic macro in Excel file. In Visual Basic strings the backslash character is not an escape character like in other programming and scripting languages. Therefore the file path must be defined in Visual Basic macro with just \ and not with \\. And leading spaces/tabs/newline characters should be also removed from file path string in Excel macro before copying the full qualified file name to clipboard.
It is of course also possible to use in UltraEdit script following line before saving the new file with full qualified name in clipboard.
UltraEdit.clipboardContent = UltraEdit.clipboardContent.replace(/^\s+/,"").replace(/\\\\/g,"\\");
The first replace removes all leading whitespaces according to Unicode definition and the second replace modifies all occurrences of \\ to just \ in file name string before the fixed full qualified file name is copied back to clipboard.
But there is really no need to use a clipboard as also written by Alexander Pavlov. The invalid full qualified file name string is already stored in a JavaScript String object with the not really good name sPath. A better name for this string variable would be sFullFileName. The UltraEdit function UltraEdit.saveAs() expects a String object as parameter. So it is also possible to use in UltraEdit script:
var sFullFileName = sPath.replace(/^\s+/,"").replace(/\\\\/g,"\\");
UltraEdit.saveAs(sFullFileName);
Note: Replacing all occurrences of \\ by just \ would be wrong for full qualified file name having a UNC path which must start with two backslashes.
Your debug output prints file name on a new line. It seems filename is preceded with a new line symbol. I think it is why it does not work. Try to trim all spaces and new lines from sPath up until the first character.
Template literals are string literals allowing use multi-line strings, eg.:
const MYSTRING = `string text line 1
string text line 2
string text line 3`;
on Delphi my actual approach is:
const MYSTRING = 'string text line 1 '+
'string text line 2 '+
'string text line 3';
has Delphi something like javascript "template literals"?
There is no such thing in Delphi. Your current approach using the + operator is the best you can do.
If you want to include variables and values which is the primary use of JS template literals, you can also consider the Format function:
http://docwiki.embarcadero.com/Libraries/Tokyo/en/System.SysUtils.Format
There are no multi-code-line constants in Delphi. You can either use the + operator to concatenate multiple lines with the sLineBreak system constant like this:
MYSTRING = 'line 1' + sLineBreak + 'line 2' + sLineBreak + 'line 3';
(You can format that across multiple lines if you want) or if you don't need cross-platform code you can do this:
MYSTRING = 'line 1'#13#10'line 2'#13#10'line 3';
When using literal characters, you don't have to use the + operator.
I have a string
String :='this is my string | yes';
I need delphi to get whatever the text is after the |
So something like:
getTextAftertoCharacter('|',String);
This should return "yes" in the example above.
Has Delphi get a function for this?
I'm not aware of a single function that does this. I think the easiest way would be to use Pos and then Copy:
answer := Copy(str, Pos('|', str) + 1, Length(str));
Start character is at Pos('|', str) + 1, amount of characters to copy is actually Length(str)-Pos('|', str), but passing a greater value to Copy also works.
Note: this will return the whole contents of str if there is no '|'. Check for Pos('|', str) being non-zero if you need different behavior.
You can use Controls.GetLongHint():
GetLongHint(String);
That's because the separator of a two part hint is a |. In your example it would return ' yes', with the leading space. If | is not found, the function returns the String.
I'd use then following code:
Trim(RightStr(Text, Length(Text)-LastDelimiter('|', Text)));
It'll locate the last delimiter in the string and I used Trim to get rid of the whitespace. LastDelimiter can take more than one delimiter which may be usefull. If no delimiter is found it will return the whole string.
I have some HAML views in my Rails project that are used to send files to the user. They're not rendered as HTML, just plain text files that get downloaded. These files have to match a very specific format, and the format has an idiosyncrasy that ends up requiring every second line to end with a tab character.
Line 0a\t01234
Line 0b\t
Line 1a\t12345
Line 1b\t
Line 2a\t23456
Line 2b\t
The a lines have have their tab characters printed fine, but the b lines do not. If I add any non-whitespace characters after the tab character, the tab gets printed. But when it's the last character on the line, it does not.
My view looks like
- #line_pairs.each do |line_pair|
= line_pair.a.words + "\t" + line_pair.a.numbers
= line_pair.b.words + "\t"
I'm sure that the tab character is not there (my editor shows them visually). There also is no space or anything of the like. I just get
Line 0a\t01234
Line 0b
Line 1a\t12345
Line 1b
Line 2a\t23456
Line 2b
Is there any way to fix this? Thanks for any help.
The haml documentation says that tilde (~) acts just like = but preserves whitespace.
Does this work?
- #line_pairs.each do |line_pair|
~ line_pair.a.words + "\t" + line_pair.a.numbers
~ line_pair.b.words + "\t"
Try :preserve
:preserve
- #line_pairs.each do |line_pair|
The proper solution as pointed out by matt is actually to just use ERB, as HAML is not meant to fill needs around controlling whitespace at this level of detail.
I am modifying a delphi app.In it I'm getting a text from a combo box. The problem is that when I save the text in the table, it contains a carriage return. In debug mode it shows like this.
newStr := 'Projector Ex320u-st Short Throw '#$A'1024 X 768 2700lm'
Then I have put
newStr := StringReplace(newStr,'#$A','',[rfReplaceAll]);
to remove the '#$A' thing. But this doesn't remove it.
Is there any other way to do this..
Thanks
Remove the quotes around the #$A:
newStr := StringReplace(newStr,#$A,'',[rfReplaceAll]);
The # tells delphi that you are specifying a character by its numerical code.
The $ says you are specifying in Hexadecimal.
The A is the value.
With the quotes you are searching for the presence of the #$A characters in the string, which aren't found, so nothing is replaced.
Adapted from http://www.delphipages.com/forum/showthread.php?t=195756
The '#' denotes an ASCII character followed by a byte value (0..255).
The $A is hexadecimal which equals 10 and $D is hexadecimal which equals 13.
#$A and #$D (or #10 and #13) are ASCII line feed and carriage return characters respectively.
Line feed = ASCII character $A (hex) or 10 (dec): #$A or #10
Carriage return = ASCII character $D (hex) or 13 (dec): #$D or #13
So if you wanted to add 'Ok' and another line:
Memo.Lines.Add('Ok' + #13#10)
or
Memo.Lines.Add('Ok' + #$D#$A)
To remove the control characters (and white spaces) from the beginning
and end of a string:
MyString := Trim(MyString)
Why doesn't Pos() find them?
That is how Delphi displays control characters
to you, if you were to do Pos(#13, MyString) or Pos(#10, MyString) then it
would return the position.