The Multifunctioning DBA

Nov 25 2011   3:33PM GMT

Powershell Truncate a String

Colin Smith Colin Smith Profile: Colin Smith

I am working on a script where I need to push some data into an oracle database. That is easy enough as I know that I can use sqlplus to execute my query into oracle but, the Oracle column that I am putting data into cannot be ny more than 10 characters. Some of the data that I want to put in is more than 10 characters so that is a problem. Now the data that I am pushing in does not matter if it gets truncated so do not do this unless that is OK. This is very simple though.

PS C:\Documents and Settings\cosmith> $string = “thisismyverylongstring”
PS C:\Documents and Settings\cosmith> $string.Length
PS C:\Documents and Settings\cosmith> $string1 = $string.Substring(0,10)
PS C:\Documents and Settings\cosmith> $string1.length
PS C:\Documents and Settings\cosmith> $string1
PS C:\Documents and Settings\cosmith>

So as you can see, using the substring function makes this very easy. Just pass it the index that you want to start with and the index that you want to end with.

Hope this helps

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: