TextandDocMgt.pdf


Preview of PDF document textanddocmgt.pdf

Page 1 2 3 4 5 6 7 8 9 10 11 12 13

Text preview


Page 3 of 13

Lecture 8 – Working with Strings and Document Mgt

When comparing strings you are comparing the total of the Unicode values. Since uppercase letters
have a lower value than lowercase, the output, “-1” indicating that string $text2 is less in value than
string $text. A “1” would indicate that $text2 is greater than $text and a “0” would indicate a perfect
match.
Alternative comparison methods are:


the Equals method, which always also does a case-sensitive comparison, and provides a
boolean value. Type: $text.Equals($text1)



-match parameter which does a case insensitive comparison, but adding the –cmatch will do a
case sensitive comparison like equals and CompareTo.


Type: $text –match $text1 #notice the result is true because match
uses a case insensitive comparison by default.



Type: $text –cmatch $text1 #result is same as with Equals because if is
comparing case.
You can also use the Contains method
to compare if a character or group of
characters exists in the string. The
methods StartsWith and EndsWith are
also very useful and like the

Figure 4: Comparing Strings

CompareTo method they are all case
sensitive by default.

Type: $text.Contains(“SYS”)
The Contains method returns True if the target text can be found and False if the target text cannot.
.2

Combining Strings

Combining strings is one of the most common operations in administration (technically called
concatenation). A typical use is when you want to output some information to the console by
combining some literal strings with variable values. To combine strings you can use the “+” or the join
operators to combine multiple strings into one string
The second method uses the join
operator. The strings to be joined
are to the left of the join operator
and the delimiter, in this case a
space, is to the right of the
operator. The strings are
appended in the order that they
Figure 5: Combining Strings with the "+" Operator