Mergefield Formatting - ms-word

How can I format my MERGEFIELD to show a suffix for Kilometers, i.e. "kms".
{MERGEFIELD distance /# kms} doesn't work. It results only in kms and omits the data.

The \# switch is a numeric format switch that requires a formatting code in double quotation marks. Once the formatting code is in place, the additional text can be added in single quotation marks. As such, this code:
{ MERGEFIELD Distance \# "# 'kms' " }
will append "kms" to any raw number (no commas, decimal point, or other formatting). To see a comprehensive explanation of formatting field codes that includes additional formatting options, please refer to Insert and format field codes in Word 2010 (or the equivalent article for other versions of Word).

Related

How can I see a string without newline characters with correct format in VS Code debuggin?

When I want to debug my code (C#) in VS Code, I see that string values which have newline in them are shown in a non-legible format.
For example, this is what I see:
"\n insert into DailyCounts (EntityTypeGuid, UtcDate, Count)\n \n select \n 'f4e46fc3-919c-11ed-878d-0242c0a82002',\n date(UtcDate),\n count(*)\n from Social.Comments\n \n group by\n 'f4e46fc3-919c-11ed-878d-0242c0a82002',\n date(UtcDate)\n \n on duplicate key update\n Count=values(Count)\n "
I want to see it in correct format like:
insert into DailyCounts (EntityTypeGuid, UtcDate, Count)
select
'f4e46fc3-919c-11ed-878d-0242c0a82002',
date(UtcDate),
count(*)
from Social.Comments
group by
'f4e46fc3-919c-11ed-878d-0242c0a82002',
date(UtcDate)
on duplicate key update
Count=values(Count)
How can I see strings as formatted when debugging in VS Code?
Format specifiers can help with your problem: https://learn.microsoft.com/en-us/visualstudio/debugger/format-specifiers-in-csharp?view=vs-2022.
There is a specifier called nq (no quote) supported by offical C# debugger, and it can reverse escaped strings. You can see json and json,nq produce two different outputs in the picture below.
However, WATCH panel only shows the first line if you don't hover your mouse above the expression:

officejs : Search Word document using regular expression

I want to search strings like "number 1" or "number 152" or "number 36985".
In all above strings "number " will be constant but digits will change and can have any length.
I tried Search option using wildcard but it doesn't seem to work.
basic regEx operators like + seem to not work.
I tried 'number*[1-9]*' and 'number*[1-9]+' but no luck.
This regular expression only selects upto one digit. e.g. If the string is 'number 12345' it only matches number 12345 (the part which is in bold).
Does anyone know how to do this?
Word doesn't use regular expressions in its search (Find) functionality. It has its own set of wildcard rules. These are very similar to RegEx, but not identical and not as powerful.
Using Word's wildcards, the search text below locates the examples given in the question. (Note that the semicolon separator in 1;100 may be soemthing else, depending on the list separator set in Windows (or on the Mac). My European locale uses a semicolon; the United States would use a comma, for example.
"number [0-9]{1;100}"
The 100 is an arbitrary number I chose for the maximum number of repeats of the search term just before it. Depending on how long you expect a number to be, this can be much smaller...
The logic of the search text is: number is a literal; the valid range of characters following the literal are 0 through 9; there may be one to one hundred of these characters - anything in that range is a match.
The only way RegEx can be used in Word is to extract a string and run the search on the string. But this dissociates the string from the document, meaning Word-specific content (formatting, fields, etc.) will be lost.
Try putting < and > on the ends of your search string to indicate the beginning and ending of the desired strings. This works for me: '<number [1-9]*>'. So does '<number [1-9]#>' which is probably what you want. Note that in Word wildcards the # is used where + is used in other RegEx systems.

Regular expression in Swift to validate Cardholder name

I am looking for a regular expression to use in Swift to validate cardholder name for a credit card. I am looking for a regEx which:
Has minimum 2 and maximum of 26 characters
Accept dashes (-) and apostrophes (') only and no other special character
Capital and small alphabets and no numbers.
Should not start with a blank space.
I was using this
"^[^-\\s][\\p{L}\\-'\\s]{2,26}$"
but it only accepts dash (-) no apostrophe (')
try with this regex
(?<! )[-a-zA-Z' ]{2,26}
see here
https://regex101.com/r/0UVvR1/1
Guessing from your description, this is what you are looking for:
^[\p{L}'-][\p{L}' -]{1,25}$
Demo
A few remarks:
you propbably do not want to allow all possible white-space chars [\r\n\t\f\v ] but just spaces.
you have to adjust the allowed lenght of the second string if you add a 1st group that does not include space and dash (since that group contributs an additional character).
with \p{L} you allow any kind of letter from any language (which is good); otherwise use [a-zA-z] if just want to allow the regular (ASCII) alphabet.
PS: Do not forget to escape the pattern properly: "^[\\p{L}'][\\p{L}' -]{1,25}$"

Swift 4 Programming Triple Quotes

What is meant, when they say "it matches the indentation of the closing quote?
“Use three double quotes (""") for strings that take up multiple lines. Indentation at the start of each quoted line is removed, as long as it matches the indentation of the closing quote. For example:
let quotation = """
Even though there's whitespace to the left,
the actual lines aren't indented.
Except for this line.
Double quotes (") can appear without being escaped.
I still have (apples + oranges) pieces of fruit.
"""
Create arrays and dictionaries using brackets ([]), and access their elements by writing the index or key in brackets. A comma is allowed after the last element.”
Excerpt From: Apple Inc. “The Swift Programming Language (Swift 4).” iBooks. https://itunes.apple.com/us/book/the-swift-programming-language-swift-4/id881256329?mt=11
These are the three scenarios I could think of to explain this:
Here the text and the triple quotes are aligned to the left
Check ouput, here the text is stored and print without a spaces at the begining of each paragraph.
let textSample1 = """
Test 1: Hello how are you welcome to the test
something else is written here
that's enough said
"""
print(textSample1)
Here the text has spacing at the begining but the triple quotes are aligned to the left
Check ouput, here the text is stored and print with spaces at the begining of each paragraph because the tripe quotes places at the left and they are taking into consideration those spaces in the paragraphs.
let textSample2 = """
Test 2: Hello how are you welcome to the test
something else is written here
that's enough said
"""
print(textSample2)
Here the text has spacing at the begining and the triple quotes also are spaced to match the text
Check ouput, here the text is stored and print without spaces at the begining though we have put spaces at the beginging, this is because the triple quotes are places at the same level as the text instead of the spaces so they spaces are ignored. I found this one handy when you want to store multi line text in code but wanted to wanted to maintain some code formatting among other uses to this.
let textSample3 = """
Test 3: Hello how are you welcome to the test
something else is written here
that's enough said
"""
print(textSample3)
OUTPUTS:
Test 1: Hello how are you welcome to the test
something else is written here
that's enough said
Test 2: Hello how are you welcome to the test
something else is written here
that's enough said
Test 3: Hello how are you welcome to the test
something else is written here
that's enough said

zip code + 4 mail merge treated like an arithmetic expression

I'm trying to do a simple mail merge in Word 2010 but when I insert an excel field that's supposed to represent a zip code from Connecticut (ie. 06880) I am having 2 problems:
the leading zero gets suppressed such as 06880 becoming 6880 instead. I know that I can at least toggle field code to make it so it works as {MERGEFIELD ZipCode # 00000} and that at least works.
but here's the real problem I can't seem to figure out:
A zip+4 field such as 06470-5530 gets treated like an arithmetic expression. 6470 - 5530 = 940 so by using above formula instead it becomes 00940 which is wrong.
Perhaps is there something in my excel spreadsheet or an option in Word that I need to set to make this properly work? Please advise, thanks.
See macropod's post in this conversation
As long as the ZIP codes are reaching Word (with or without "-" signs in the 5+4 format ZIPs, his field code should sort things out. However, if you are mixing text and numeric formats in your Excel column, there is a danger that the OLE DB provider or ODBC driver - if that is what you are using to get the data - will treat the column as numeric and return all the text values as 0.
Yes, Word sometimes treats text strings as numeric expressions as you have noticed. It will do that when you try to apply a numeric format, or when you try to do a calculation in an { = } field, when you sum table cell contents in an { = } field, or when Word decides to do a numeric comparison in (say) an { IF } field - in the latter case you can get Word to treat the expression as a string by surrounding the comparands by double-quotes.
in Excel, to force the string data type when entering data that looks like a number, a date, a fraction etc. but is not numeric (zip, phone number, etc.) simply type an apostrophe before the data.
=06470 will be interpreted as a the number 6470 but ='06470 will be the string "06470"
The simplest fix I've found is to save the Excel file as CSV. Word takes it all at face value then.