Scripting Blog [archived]

Formerly known as the "Hey, Scripting Guy!" blog

How Can I Extract the Text Between the Header and Footer in a Text File?

(image) Hey, Scripting Guy! How can I extract the text between the header and footer in a text file?-- LL(image) (image) (image) Hey, LL. Before we answer your question we should point out that, depending on when you’re reading this, you might be missing Day 1 of Windows PowerShell Week. Even as we speak the lovely and talented Jean Ross ...

How Can I Split a String Only on Specific Instances of a Character?

(image) Hey, Scripting Guy! I have a series of string values that I need to convert to an array, splitting the value on the ampersand (&). However, if the ampersand is followed by amp (in other words, if the string is &amp) I don’t want to split the string at that point. How do I do that?-- AK(image) (image) (image) Hey, AK. We ...

How Can I Remove Blank Spaces Before and After a String Value?

(image) Hey, Scripting Guy! We have a custom in-house application that writes data to a log file. The problem is that the data often has a bunch of blank spaces before and after it. How can I remove all the blank spaces that come before and after my data?-- KS(image) (image) (image) Hey, KS. You might find this hard to believe, but the ...

How Can I Truncate Names to a Maximum of 16 Characters?

(image) Hey, Scripting Guy! How can I truncate names to a maximum of 16 characters?-- BN(image) (image) (image) Hey, BN. Brace yourself: it’s time for another trip down memory lane. When one of the Scripting Guys was going to college, he took a temporary summer job with the Green Giant Corporation, working in the office that oversaw the ...

How Can I Convert a DN to this Format: finance.fabrikam.com/Users?

(image) Hey, Scripting Guy! How can I convert a DN to this format: finance.fabrikam.com/Users?-- CW(image) (image) (image) Hey, CW. You know, this is a pretty good question; in fact, we should have used it for the Winter Scripting Games. Ah, but, on second thought, maybe it’s a good thing we didn’t use it. Why not? Well, because all ...