May 4, 2012 at 12:09 pm
I am having a problem in gettin this regex statemnent to work.
if (a.FullPath.StartsWith("Q:"))
monitoringpath = "\\\\eldorado\sasknowledge\\Programs\\Data Distribution\\CollectionPoint";
FullPath2 = Regex.Replace(a.FullPath, "Q:", "");
FullPath2 = monitoringpath + FullPath2;
The a.FullPath variable contains: Q:\1111_drop1.TXT
The end result is:
\\eldorado\sasknowledge\Programs\Data Distribution\CollectionPointQ:\1111_drop1.TXT
I expect the Q: in the .FullPath to be removed but it isn't happening. Any ideas why this is happening?
Thanks,
A clever person solves a problem. A wise person avoids it. ~ Einstein
select cast (0x5365616E204465596F756E67 as varchar(128))
May 4, 2012 at 12:31 pm
Try
$FullPath2 = [Regex]::Replace(a.FullPath, "Q:", "")
May 4, 2012 at 12:56 pm
Oops I got my environments mixed up. I am actually working in Visual Studio .Net and my code is C#. Your code is the equivalent of my code in C#. Only different being how the variable looks and how you call the regex replace function.
bruce 1565 (5/4/2012)
Try
$FullPath2 = [Regex]::Replace(a.FullPath, "Q:", "")
A clever person solves a problem. A wise person avoids it. ~ Einstein
select cast (0x5365616E204465596F756E67 as varchar(128))
May 8, 2012 at 3:17 am
I am just wondering why you aren't string's Replace or even Substring?
If you know the text or have the variable surely something like the following will do:
FullPath2 = a.FullPath.Substring("Q:".Length);
As you can see, you can replace "Q:" in your code with a defined string variable or constant in order to make it less brittle or you could decide that you could hard code the value as 2.
Gaz
-- Stop your grinnin' and drop your linen...they're everywhere!!!
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply