Sign in to follow this  
Followers 0
arcticpup

String headache

6 posts in this topic

Hi,

Having given myself a headache trying to work this one out, looking at stringsplit and searching the forums etc.....

What I want to do is read a reg value as a variable (so far so good)

This key will usually(but not always) contain a backslash (it is refering to a servername and sql instance so would normally by server\instance) but obviously server and instance name may change in name and length.

what I want to do is read this as a variable and strip out everything after the backslash (including the backslash itself)

Any help would be appreciated

Thanks

Share this post


Link to post
Share on other sites



Hi,

Having given myself a headache trying to work this one out, looking at stringsplit and searching the forums etc.....

What I want to do is read a reg value as a variable (so far so good)

This key will usually(but not always) contain a backslash (it is refering to a servername and sql instance so would normally by server\instance) but obviously server and instance name may change in name and length.

what I want to do is read this as a variable and strip out everything after the backslash (including the backslash itself)

Any help would be appreciated

Thanks

Do you have some code already? (To start)

Share this post


Link to post
Share on other sites

$sServ = StringRegExp($sValue, '(.*)\\', 1)
If IsArray($sServ) Then 
    ; Success
Else
    ; Failure
EndIf

If it may not contain a backslash then you may want to change '\\' to '\\?'.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Hi,

Having given myself a headache trying to work this one out, looking at stringsplit and searching the forums etc.....

What I want to do is read a reg value as a variable (so far so good)

This key will usually(but not always) contain a backslash (it is refering to a servername and sql instance so would normally by server\instance) but obviously server and instance name may change in name and length.

what I want to do is read this as a variable and strip out everything after the backslash (including the backslash itself)

Any help would be appreciated

Thanks

RegexReplace!

Pattern:

CODE
\\.*

Replace:

CODE

Should look like:

CODE
$ServerName = StringRegExpReplace($Text, "\\.*", "", 0)

Also there is an SRE tester in my sig thatw ill help you a lot for learning how to do these=)

Edited by Szhlopp

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Edit: DAMN you'll are fast O_O.

They went more in depth than I did :P.

Edited by Drew

Share this post


Link to post
Share on other sites

RegexReplace!

Pattern:

CODE
\\.*

Replace:

CODE

Should look like:

CODE
$ServerName = StringRegExpReplace($Text, "\\.*", "", 0)

Also there is an SRE tester in my sig thatw ill help you a lot for learning how to do these=)

Fantastic! Such a simple solution. Many thanks for all your advice! :P

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0