Phone800.366.3472 SupportGet Support DocumentationDocumentation Resource CenterResource Center
search
close
Open Menu

Synergex Blog


New string features coming with Synergy/DE 11

By Jerry Fawcett, Posted on August 19, 2019 at 8:58 am

Avatar

Synergy/DE 11 is bringing many new features, and among those additions are some exciting new abilities within the String class. All of these powerful new features are available in both traditional and Synergy .NET.

When dealing with strings, keep in mind that a string is immutable (fancy word for unchangeable), so any time a string variable is changed, a new string variable is created.

First, let me list the new methods added, along with existing methods that include new overloads to the String class: 

String.IsNullorEmpty(@string) , boolean
  • Parameter: String to interrogate for null or empty value
  • Return value: Boolean value indicating whether the string is null or empty
String.IsNullorWhitespace(@string) , boolean
  • Parameter: String to interrogate for null or white-space characters
  • Return value: Boolean value indicating whether the string contains null or white-space characters

New overloads to give precise control on how a string is trimmed:

String.Trim() ,string			(exists prior to version 11)
  • Parameter: None
  • Return value: String with leading and trailing white-space characters removed
String.Trim(@string) ,string 
  • Parameter: Character(s) to be removed from the string’s beginning and end
  • Return value: Returned string with passed-in character(s) removed from the beginning and end
String.TrimStart(@string) ,string
String.TrimEnd(@string) ,string
  • Parameter: Character(s) to remove from either the string’s start or end
  • Return value: String with all instances of character(s) removed from start or end

New methods to control how characters are removed or inserted into a string:

String.Remove(N) ,string
  • Parameter: Starting position in the string to remove all characters until its end
  • Return value: String with all characters from passed starting position to end removed
String.Remove(N) ,string
  • Parameter: Starting position in the string to remove all characters until its end
  • Return value: String with all characters from passed starting position to end removed
String.Insert(N, @string) ,string
  • Parameters:
    1. Starting position to insert string passed as parameter 2
    2. String to be inserted
  • Return value: Returned string with sting passed in parameter 2 inserted

New overloads to give more control on concatenating strings together:

String.Concat(@string, @string) ,string	(exists prior to version 11)
String.Concat(@string, @string, @string) ,string
String.Concat(@string, @string, @string, @string) ,string
String.Concat([#]@string) ,string
  • Parameters:
    1. Two strings to concatenate together
    2. Three strings to concatenate together
    3. Four strings to concatenate together
    4. Dynamic string array to concatenate all elements together
  • Return value: Returned string after concatenation operation

New overloads to locate the position of a substring in a string:

String.IndexOf(A1) ,int			(exists prior to version 11)
String.IndexOf(A1, N) ,int
String.IndexOf(A1, N, N) ,int		(exists prior to version 11)
  • Parameters:
    1. Character(s) to find in string
    2. Character(s) to find in string starting at position specified in parameter 2
    3. Character(s) to find in string starting at position specified in parameter 2 for the length of parameter 3
  • Return value: Integer value with first position of passed character(s)

New overloads to find the last occurrence of a substring in a string:

String.LastIndexOf(A1) ,int		(exists prior to version 11)
String.LastIndexOf(A1,N) ,int
String.LastIndexOf(A1,N,N) ,int		(exists prior to version 11)

Parameters:

  • Parameters
    1. Numeric value of the starting position to begin returning the substring
    2. Numeric value of the length of the substring to return
  • Return value: Returned substring with value from the specified starting and length values

New methods to create an array from a delimited string:

String.Split(A1) ,[#]string
String.Split(A1, StringSplitOptions) ,[#]string (see below for the StringSplitOptions enumeration)
  • Parameters:
    1. Character(s) to use a delimiter
    2. Enumeration StringSplitOptions to control if empty elements are created
    3. Return value: Dynamic string array to be populated with the contents of the passed string

New overload to use the replace method on alphas:

String.Replace(A, A) ,string
  • Parameters:
    1. Alpha value to be replaced by parameter 2
    2. Alpha value to replace all occurrences of parameter 1 in string
  • Return value: Returned string with all occurrences of parameter 1 replaced by parameter 2
String.Replace(@string, @string) ,string 	(exists prior to version 11)
  • Parameters
    1. String value to be replaced by parameter 2
    2. String value to replace all occurrences of parameter 1 in string
  • Return value: Returned string with all occurrences of parameter 1 replaced by parameter 2

And finally, the enumeration StringSplitOptions, which is used with the Split method to control if empty elements are created when creating the string array:

public enum StringSplitOptions
    None		,0
    RemoveEmptyEntries	,1

You can find details on all String members in the System.String topic in the Synergy/DE documentation.

As I mentioned earlier, some of the above are brand new methods (Insert, IsNullorWhitespace, Remove, Split, TrimEnd, TrimStart) added to the System.String class, while others are new overload methods added to existing methods to provide additional functionality. Interestingly, the runtime itself will make use of the String.Concat method when strings are added together (e.g., string1 + string), as it is efficient and generates fewer temporary variables.

Now let’s take a look at one of the new methods. Using the new Split method, we can populate a dynamic array from a delimited string. Say we have a string containing the following:

mystring = “Bob, Mary, Joe, Jack,,,, Fred, Henry, Tom”

We’d like for the values between the commas to be elements in an array, but we don’t want the commas without values between them to become empty elements in the array. This can easily be accomplished with the String.Split method using the syntax below:

stringarray = mystring.split(“,” , StringSplitOptions.RemoveEmptyEntries)

Passing the quoted comma as the first parameter tells the Split method that a comma is the delimiter to look for in the string. Also, for even more control, the delimiter can consist of any number of characters.  There is no need to instantiate the dynamic array, as the dynamic array will automatically be instantiated by the Split method. The result of the above operation will be that the dynamic array stringarray will contain elements with the names that are separated by commas in the string mystring and no empty elements (due to passing StringSplitOptions.RemoveEmptyEntries as the second parameter) for the commas with no values between them:

stringarray[1] = “Bob”
stringarray[2] = “Mary”
stringarray[3] = “Joe”
stringarray[4] = “Jack”
stringarray[5] = “Fred”
stringarray[6] = “Henry”
stringarray[7] = “Tom”

As you can see, the enhancements to the String class are more than enough reason to upgrade to Synergy/DE 11 when it’s released. If you can’t wait and want to try these new capabilities now, the version 11 beta is available in the Resource Center for download. Don’t forget to set your Synergy/DE documentation to the “Beta” version in the version drop-down near the top of the screen.

And wait, there’s more! Now that you’re aware of the new and powerful methods added to the String class, be sure to also check out the new StringBuilder class added to version 11.


Using the Power of PowerShell with Synergy

By Jerry Fawcett, Posted on November 30, 2018 at 1:56 pm

Avatar

Like it or not, change is inevitable. Now that you’ve mastered the command prompt, it’s slowly but surely being replaced by PowerShell. Actually, this process was started by Microsoft way back in 2002, which is how PowerShell came about in the first place.

Starting with Windows 10, the PowerShell command prompt has replaced the Command Prompt as the default. (To control this, toggle the Taskbar setting “Replace Command Prompt with Windows PowerShell in the menu when I right-click the start button or press Widows Key+X.”)

Comparing Command Prompt and Windows PowerShell

PowerShell Up

So you opened a PowerShell window and now everything you try results in copious output in ominous red text? Luckily for those of us who are learning PowerShell from the ground up, PowerShell comes with very complete and verbose help. Just type

get-help cmdlet

For example, you’d use “get-help where” to learn about the powerful where object. However, if you’re familiar with any OO language you’ll probably find PowerShell quite natural.

One would think PowerShell is a Windows-only tool, but surprisingly, Microsoft has made it open source, and it’s also available on macOS, CentOS, and Ubuntu.

You can use PowerShell together with Synergy in many ways, and I’d like to share some of what I’ve learned. Using the power (pun intended) of PowerShell can be helpful in getting information on Synergy products from a machine. Getting this information without PowerShell would be difficult—especially for a non-technical person—and potentially error prone.

By preceding a PowerShell command with “powershell” you can actually run it from a DOS command line without opening a PowerShell console, as the command is passed to the PowerShell processor as a parameter. However, by doing this, you’ll lose the awesome power of tab completion available in the PowerShell console. Try it: Open a DOS command window and type “powershell /?”.

A demo of get-help cmdlet

The PowerShell is Yours!

(At this point, I feel I must tell you that Synergy tools are currently not supported in a PowerShell environment. Ideas post, anyone?)
To list all Synergy products:

Get-WmiObject -ComputerName COMPUTERNAME -Class Win32_Product | sort-object Name | Select-Object Name |where{$_.name -like "*Synergy*"}
Output –
Name
----
Synergy DBL Integration for Visual Studio 10.3.3f
Synergy/DE (X64) 10.3.3f
Synergy/DE 10.3.3f
Synergy/DE Online Manuals 10.3.3
Synergy/DE xfNetLink .NET Edition (X64) 10.3.3f

To list all Windows updates on a machine:

(New-Object -ComObject "Microsoft.Update.Session").CreateUpdateSearcher().QueryHistory(0,(New-Object -ComObject "Microsoft.Update.Session").CreateUpdateSearcher().GetTotalHistoryCount()) | Select-Object Title, Description, Date

If you need to retrieve all events from the Windows Event viewer that deal with the runtime, simply have the end user double-click on a batch file containing the command below and send you the file it creates (C:\temp\SynEventViewerEntries.txt).

powershell Get-EventLog -logname application -source dbr^|Format-List MachineName, Message, TimeGenerated ^|out-file C:\temp\SynEventViewerEntries.txt

To list all installed software on a machine,

Get-WmiObject -ComputerName FAWCETT -Class Win32_Product|Sort-Object name| Select-Object Name, Version

Just so you’re aware, when you get started, you may find no script will successfully run, because script execution is disabled by default. You can enable it as follows:

First, to verify the PowerShell’s execution policy, type

Get-ExecutionPolicy

You’ll probably see

Default is Restricted

To enable execution, you must open the PowerShell command prompt as an Administrator and type

Set-ExecutionPolicy Unrestricted –Force

And just for fun, if— like me—you miss the Windows Experience score that was first introduced with Windows Vista but is now removed, you can use PowerShell to get your machine’s Windows Experience score. The Windows Experience score is a benchmark that measures your PC’s performance in five categories: processor, memory, graphics, gaming graphics, and hard disk performance. The score is the lowest of these benchmarks. To get your machine’s score, run

Get-WmiObject -Class Win32_WinSAT

If you want to learn more, you can search online. Every PowerShell topic I searched for resulted in a wealth of information.

More Power(Shell) to you!

Some good resources:

Microsoft Official PowerShell documentation

Getting Started with Windows PowerShell

PowerShell: The smart person’s guide


Don't miss a post!

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Recent Posts Tag Cloud Archives