Auric__ wrote on 28 feb 2013 in microsoft.public.scripting.vbscript:
> Evertjan. wrote:
>
>> Mayayana wrote on 28 feb 2013 in microsoft.public.scripting.vbscript:
>>
>>> You might want to download the help files for Windows
>>> Script Host:
>>>
>>>
http://www.microsoft.com/downloads/details.aspx?FamilyId=01592C48-207
>>> D- 4BE1-8A76-1C4099D7BBB9
>>>
>>> It's reasonably good documentation, and there are
>>> not really a lot of VBScript methods to learn. Things
>>> like Len, Right, Mid, InStr are basics that one can't
>>> really write a script without.
>>
>> Don't discount Regular Expressions, when using regex a fixed position
>> is not even necessary for replacing or deleting parts of a string.
>> It takes some learning, but you will enjoy this the rest of your
>> life.
>
> In this case, regexes aren't really needed, since the op wants "only
> the part of the namefile beetwen the eighth character and the
> sixteenth character", i.e. Mid(file.Name, 8, 9) as I posted earlier.
> IMO a regex is overkill for this, especially since the string handling
> stuff is built into the language (and has been for about a thousand
> years).
>
> Plus, changing the Mid() line (in case the format of the filenames
> changes) is pretty straightforward... but the regex looks like line
> noise to me.
What nonsense, to call anything you do not understand an overkill.
To me, and I speak some Algol, Fortran and fluently ancient Basic,
regex is simpler than counting places.
Probably the OP did specify positions, because he did not understand the
ease of using the quoted underscores as delimiters, not needing to specify
the length of the numbers.
>> Or use the split():
>>
>> s1 = "xxxxxx_namefile1_xxxxxxxxxx.pdf"
>> s2 = split(s1,"_")
>> s3 = s2(1) & ".pdf"
>>
>> [tested on IE10]
>>
>> ============================
>>
>> Off topic, I know:
>> Javascript does the same, but looks more elegant:
>>
>> var s1 = 'xxxxxx_namefile1_xxxxxxxxxx.pdf'
>> var s3 = s1.replace(/^[^_]+_([^_]+)[^.]+(.*)$/, '$1$2');
>>
>> Or use the split():
>>
>> var s1 = 'xxxxxx_namefile1_xxxxxxxxxx.pdf';
>> var s3 = s1.split('_')[1] + '.pdf';
>
> More overkill, IMO. Why build an array when you only need one piece of
> it?
I would understand if it were your 'humble' opinion, but it is not, as a
slit works as fast as en inferred split, using the mid() function.
Mind, I don't say my examples are better, but let us give the OP to decide
what [s]he likes best.
> If the location of the underscores differed from file to file, this
> might make sense, but not with the example names the op posted.
Nonsense again, it makes a lot of sense,
the ways are just different, not better or worse.