 




<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The VBScript Network and Systems Administrator&#039;s Cafe &#187; string</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/tag/string/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator</link>
	<description></description>
	<lastBuildDate>Tue, 11 Oct 2011 18:36:53 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Easy String Searches with the VBScript Instr function</title>
		<link>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/easy-string-searches-with-the-vbscript-instr-function/</link>
		<comments>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/easy-string-searches-with-the-vbscript-instr-function/#comments</comments>
		<pubDate>Fri, 30 Jan 2009 01:30:43 +0000</pubDate>
		<dc:creator>Jerry Lees</dc:creator>
				<category><![CDATA[InStr function]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[String manipulation]]></category>
		<category><![CDATA[strings]]></category>
		<category><![CDATA[VBScript]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/?p=104</guid>
		<description><![CDATA[I recently had a situation where I needed to find string inside a string to parse the larger string into usable and separateÂ chunks of data. In writing this script, I realized I&#8217;ve not shared this gem of a function with you previously&#8230; and it really makes matters easier when you are manipulating strings. That [...]]]></description>
				<content:encoded><![CDATA[<p>I recently had a situation where I needed to find string inside a string to parse the larger string into usable and separateÂ chunks of data. In writing this script, I realized I&#8217;ve not shared this gem of a function with you previously&#8230; and it really makes matters easier when you are manipulating strings.</p>
<p>That function is the Instr function. When configured with the proper parameters, by default, it will return the FIRST location in a string where a sub-string occurs. (Hint: this is where a mid() function would come in handy after you have that starting location). If the sub-string is not found, the function returns 0. The syntax is as follows:</p>
<blockquote><p><strong>Instr(StartPostion, StringToSearch,StringtoFind, Compare)</strong></p></blockquote>
<p> </p>
<p>Â The script I wrote really is a blog entry of it&#8217;s own, and will be, but I wanted to first introduce you to this great function and let you have a chance to play with it and see some code in action. Below is an example script that takes a string and searched for specific sub strings, then returns the location in the string where the sub string occurs.</p>
<p> </p>
<p><span>Option explicit<br />
Dim StrSource</span></p>
<p><span>StrSource = &#8220;Now I can find a word In a long string of words in a sentance.&#8221;</span></p>
<p><span>WScript.Echo(InStr(1,StrSource,&#8221;In&#8221;))<br />
WScript.Echo(InStr(1,StrSource,&#8221;in&#8221;))<br />
WScript.Echo(InStr(1,StrSource,&#8221; in &#8220;))<br />
WScript.Echo(InStr(1,StrSource,&#8221;now&#8221;))</span></p>
<p>Below is the output from the script. Notice, the following:</p>
<ul>
<li>The case of <strong><span>in</span></strong> and <span><strong>In</strong></span> in the sub-string being searched for and the positions it returns?</li>
<li>Notice the substring &#8220;<span><strong>in</strong></span> &#8221; returns something entirely different?</li>
<li>Notice the substring <strong><span>now</span></strong> returns 0?</li>
</ul>
<p> </p>
<p>23<br />
12<br />
48<br />
0</p>
<p> </p>
<p>Enjoy!</p>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/easy-string-searches-with-the-vbscript-instr-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using special characters in VBScript strings</title>
		<link>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/special-characters-in-vbscript-strings/</link>
		<comments>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/special-characters-in-vbscript-strings/#comments</comments>
		<pubDate>Mon, 29 Dec 2008 15:21:52 +0000</pubDate>
		<dc:creator>Jerry Lees</dc:creator>
				<category><![CDATA[ASCII]]></category>
		<category><![CDATA[Special Characters]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[String manipulation]]></category>
		<category><![CDATA[strings]]></category>
		<category><![CDATA[VBScipt]]></category>
		<category><![CDATA[working with variables]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/?p=107</guid>
		<description><![CDATA[I just realized I&#8217;ve been using Visual Basic String constants in my scripts with little to no explanation. We&#8217;ll rectify that situation right now! When dealing with strings in VBScript, you occasionally need to add formatting characters to a string, so that when it is displayed on the screen or in a file it looks [...]]]></description>
				<content:encoded><![CDATA[<p>I just realized I&#8217;ve been using Visual Basic String constants in my scripts with little to no explanation. We&#8217;ll rectify that situation right now! <img src='http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>When dealing with strings in VBScript, you occasionally need to add formatting characters to a string, so that when it is displayed on the screen or in a file it looks correct. If you know your ASCII chart you can certainly preform this with a <em>&#8220;&amp; chr(X) &amp;&#8221;.</em>However, if you don&#8217;t know what ASCII value a tab is (it&#8217;s 9) then you can simply use Visual Basic&#8217;s string constants in your scripts and have the added benefit if making it easier to read!</p>
<p>The constants and their meanings are listed below:</p>
<table border="0">
<tbody>
<tr>
<td>VBTab</td>
<td>A Tab character [Chr(9)]</td>
</tr>
<tr>
<td>VBCr</td>
<td>A carriage return [Chr(13)]</td>
</tr>
<tr>
<td>VBCrLf</td>
<td>A carriage return and line feed [Chr(13) + Chr(10)]</td>
</tr>
<tr>
<td>vbBack</td>
<td>A backspace character [Chr(8)]</td>
</tr>
<tr>
<td>vbLf</td>
<td>A linefeed [Chr(10)]</td>
</tr>
<tr>
<td>vbNewLine</td>
<td>A platform-specific new line character, either [Chr(13) + Chr(10)] or [Chr(13)]</td>
</tr>
<tr>
<td>vbNullChar</td>
<td>A null character of value 0 [Chr(0)]</td>
</tr>
<tr>
<td>vbNullString</td>
<td>A string of value 0 [no Chr code]; note that this is not the same as &#8220;&#8221;</td>
</tr>
</tbody>
</table>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/special-characters-in-vbscript-strings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Very simple encryption example with VBScript</title>
		<link>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/very-simple-encryption-example-with-vbscript/</link>
		<comments>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/very-simple-encryption-example-with-vbscript/#comments</comments>
		<pubDate>Tue, 02 Dec 2008 00:55:23 +0000</pubDate>
		<dc:creator>Jerry Lees</dc:creator>
				<category><![CDATA[3des]]></category>
		<category><![CDATA[decrypt]]></category>
		<category><![CDATA[decrytption]]></category>
		<category><![CDATA[encrypt]]></category>
		<category><![CDATA[encryption]]></category>
		<category><![CDATA[mid]]></category>
		<category><![CDATA[Reverse Strings]]></category>
		<category><![CDATA[RSA]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[String manipulation]]></category>
		<category><![CDATA[StrReverse]]></category>
		<category><![CDATA[Toolkit]]></category>
		<category><![CDATA[VBScript]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/very-simple-encryption-example-with-vbscript/</guid>
		<description><![CDATA[I previously mentioned a routine that I wrote to encrypt a string. Now, before the security folks look at the code&#8230; understand this: This is intended only to obscure a string from a casual prying eye. It is NOT intended to be a replacement for true encryption like 3DES and RSA encryption. Please do NOT assume [...]]]></description>
				<content:encoded><![CDATA[<p>I previously mentioned a routine that I wrote to encrypt a string. Now, before the security folks look at the code&#8230; understand this:</p>
<p><em>This is intended only to obscure a string from a casual prying eye. It is <strong>NOT</strong> intended to be a replacement for true encryption like 3DES and RSA encryption. Please do <strong>NOT</strong> assume this routine is in any way secure or uncrackable. It is intended to only be an exercise in working with strings and is only as secure as the price you have paid for it. Nothing. <img src='http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  Furthermore, it is provided as-is without warranties and by using it you agree that all risk from it&#8217;s use is transferred to you.</em></p>
<p>&#8230;.Now that we&#8217;ve gotten the unpleasant legal disclaimer out of the way&#8230; Lets discuss the code!</p>
<p>Essentially, The code uses a variable length key to obscure the original string by iterating through the string you want obscured and adding the ASCII value of the character at each position of the original string with the ASCII value of a rotating &#8220;key character&#8221; in the key provided to generate a new ASCII value. This new ASCII value is then converted to a character and added to the newly encrypted string. The obscured string is further obscured by the fact that the original string is reversed prior to being changed. </p>
<p>This key position changes after each character in the original string is obscured. The result is the key is iterated through sequentially as the original string is encrypted and when the end of the key string is encountered the iteration through the key string is started again from the beginning of the key string until the original string is completely encrypted.</p>
<p>This process works because the ASCII values in the typical string and the typical key string when added together do not exceed 255. (The highest possible ASCII character) Essentially, Strings and Keys with ASCII values higher than 126 should not be used or the result could be unpredictable&#8211; or worse yet, an unencryptable string.</p>
<p>Now that I&#8217;ve explained a bit about the premise&#8230; Lets look at the code!</p>
<p><font color="#0000ff">Option Explicit</font></p>
<p><font color="#0000ff">Dim temp, key</font></p>
<p><font color="#0000ff">temp = &#8220;Now is the time for all good men To come To the aid of their fellow countrymen.&#8221;<br />
key = &#8220;huasHIYhkasdho1&#8243;</font></p>
<p><font color="#0000ff">temp = Encrypt(temp,key)<br />
WScript.Echo temp<br />
temp = Decrypt(temp,key)<br />
WScript.Echo temp</font></p>
<p><font color="#0000ff">Function encrypt(Str, key)<br />
 Dim lenKey, KeyPos, LenStr, x, Newstr<br />
 <br />
 Newstr = &#8220;&#8221;<br />
 lenKey = Len(key)<br />
 KeyPos = 1<br />
 LenStr = Len(Str)<br />
 str = StrReverse(str)<br />
 For x = 1 To LenStr<br />
      Newstr = Newstr &amp; chr(asc(Mid(str,x,1)) + Asc(Mid(key,KeyPos,1)))<br />
      KeyPos = keypos+1<br />
      If KeyPos &gt; lenKey Then KeyPos = 1<br />
 Next<br />
 encrypt = Newstr<br />
End Function</font></p>
<p><font color="#0000ff">Function Decrypt(str,key)<br />
 Dim lenKey, KeyPos, LenStr, x, Newstr<br />
 <br />
 Newstr = &#8220;&#8221;<br />
 lenKey = Len(key)<br />
 KeyPos = 1<br />
 LenStr = Len(Str)<br />
 <br />
 str=StrReverse(str)<br />
 For x = LenStr To 1 Step -1<br />
      Newstr = Newstr &amp; chr(asc(Mid(str,x,1)) &#8211; Asc(Mid(key,KeyPos,1)))<br />
      KeyPos = KeyPos+1<br />
      If KeyPos &gt; lenKey Then KeyPos = 1<br />
      Next<br />
      Newstr=StrReverse(Newstr)<br />
      Decrypt = Newstr<br />
End Function</font></p>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/very-simple-encryption-example-with-vbscript/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>A new found bug in VBScript that causes if then statements to return wrong comparisons (or is it?)</title>
		<link>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/a-new-found-bug-in-vbscript-that-causes-if-then-statements-to-return-wrong-comparisons-or-is-it/</link>
		<comments>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/a-new-found-bug-in-vbscript-that-causes-if-then-statements-to-return-wrong-comparisons-or-is-it/#comments</comments>
		<pubDate>Thu, 30 Oct 2008 00:00:58 +0000</pubDate>
		<dc:creator>Jerry Lees</dc:creator>
				<category><![CDATA[Integer]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[Variable Types]]></category>
		<category><![CDATA[variant]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[working with variables]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/a-new-found-bug-in-vbscript-that-causes-if-then-statements-to-return-wrong-comparisons-or-is-it/</guid>
		<description><![CDATA[In the past I&#8217;ve cautioned you on always initializing your variables and encouraged you to always declare your variable types, rather than using the default variant type in VBScript. I&#8217;ll be the first to admit I don&#8217;t follow my own advice in my examples! However, variants can be dangerous! Recently I had a situation where if [...]]]></description>
				<content:encoded><![CDATA[<p>In the past I&#8217;ve cautioned you on always initializing your variables and encouraged you to always declare your variable types, rather than using the default variant type in VBScript. I&#8217;ll be the first to admit I don&#8217;t follow my own advice in my examples! However, variants can be dangerous!</p>
<p>Recently I had a situation where if statements were returning completely not correct results and for the life of me I couldn&#8217;t figure it out! Here is an example that illustrates what was happening to me.</p>
<p><font color="#0000ff">one = 1<br />
two = 2<br />
three = 3<br />
OneBillion = 1000000000</font></p>
<p><font color="#0000ff">MyVar = inputbox(&#8220;Enter a number&#8221;)</font><font color="#0000ff">If one &lt; MyVar Then<br />
     WScript.Echo (one &amp; &#8221; is lessthan &#8221; &amp; MyVar)<br />
End If<br />
If two &lt; MyVar Then<br />
     WScript.Echo (two &amp; &#8221; is lessthan &#8221; &amp; MyVar)<br />
End If</font><font color="#0000ff"><font color="#0000ff">If three &lt; MyVar Then<br />
     WScript.Echo (three &amp; &#8221; is lessthan &#8221; &amp; MyVar)<br />
End If</font></font><font color="#0000ff"><font color="#0000ff">If OneBillion &lt; MyVar Then<br />
     WScript.Echo (OneBillion &amp; &#8221; is lessthan &#8221; &amp; MyVar)<br />
End If</font></p>
<p></font><font color="#000000">The basis of the problem is that I was taking input from a file that was a number&#8211; however I was reading the file and it was coming into the script and being used as a string by the variant variable. I then was comparing it to a number and the comparisons were not working 100% correctly. Check it out by entering several numbers into the script. Try entering 0, 1, 2, 3, and 1000000001.</font></p>
<p>The moral of the story here is to always cast your varables as a specific type or use the cint() function to convert your variant varables to numbers before doing number comparisons with a literal number and a variant variable that is supposed to contain a number.</p>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/a-new-found-bug-in-vbscript-that-causes-if-then-statements-to-return-wrong-comparisons-or-is-it/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
