Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

powershell: how to evaluate a string

Tags:

file a.txt is:

delete from test_$suffix

$a=get-content a.txt

$suffix="tableA"

how to manipulate the variable to set it as

delete from test_tableA

like image 223
Daniel Wu Avatar asked Jan 29 '11 11:01

Daniel Wu


People also ask

How do I compare strings in PowerShell?

To check to see if one object is equal to another object in PowerShell is done using the eq operator. The eq operator compares simple objects of many types such as strings, boolean values, integers and so on. When used, the eq operator will either return a boolean True or False value depending on the result.

How do I find a string in a string in PowerShell?

To find a string inside of a string with PowerShell, you can use the Substring() method. This method is found on every string object in PowerShell. The first argument to pass to the Substring() method is the position of the leftmost character.

How do you check if a string contains a Substring in PowerShell?

If you want to know in PowerShell if a string contains a particular string or word then you will need to use the -like operator or the . contains() function. The contains operator can only be used on objects or arrays just like its syntactic counterpart -in and -notin .

How do you reference a variable in a string in PowerShell?

PowerShell has another option that is easier. You can specify your variables directly in the strings. $message = "Hello, $first $last." The type of quotes you use around the string makes a difference.


1 Answers

$a=get-content a.txt $suffix="tableA"  $ExecutionContext.InvokeCommand.ExpandString($a) 
like image 93
Doug Finke Avatar answered Sep 28 '22 14:09

Doug Finke