Link to home
Start Free TrialLog in
Avatar of Robb Hill
Robb HillFlag for United States of America

asked on

.net string parse

I have a value that will be typed in a win form for the root value of an network share.

For example they might type
\\RootShare\Par4\

I might have this stored in the database as such as varchar.

\\RootShare\Par4\help\me\figure\this\out\fileconclusion.txt


If they key this value in the text box...

How would do this string compare to get the correct results.
This would need to be an exact match on the first two valuesin the string.

Keep in mind you could also have something like
\\RootShare\Par44444\help\me  (Incorrect)

or

\\RootShare\Par444\Par4  (incorrect)

or
\\RootShare\Par4\par4  (incorrect
SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Robb Hill

ASKER

after coding this more..I think i need to change this a little..
If this still is in your scope..if not..I will make a new thread and close this one.


So I think this is really going to be handled in linq.

the Winform UI gives me some network share value...could be correct or not.

At the end of the day my linq query will have a where statement that utilized a column called path in the database.

This is the full path...could be very long.

But the UI only gives me the root.

So in my where clause of the linq I need to take this value from the text box..and compare it to this value in the database which is a full path.  

So I would only want the where statement comparing this path column where the text value from the textbox is matched.

I am confused here.  Do I have to do two separate linq calls here or can I do this in one pass.

Please help
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
kaufmed..that would help in a later part of my issue..but right now its really just the winform UI to the linq query I am building.

At this point I will not be checking the physical IO.


I have a where statement that looks at a column that has the entire path.

But my UI would only pass in the root.

I need my where clause to evaluate in the where clause all of the full paths ..that had that value passed in from the text box.

I wanted to make sure I handled any execptions that could occur..or make sure that formatting doesnt mess me up from getting a good where clause
Here is a more direct example:

 var docInfo = from d in sqlDb.Docs                   
                          where d.Path == here is my issue

d.Path in the database could be....
\\test\data\WEB\images\

While the typed in value from the UI text box would only be \\test\data


So on the where clause I would want to get all of these paths that matched...nothing more or less.

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
so essentially this would push the value from the text box into the path object...so assuming all was correct...this startswith might work...


If root in this case ....\\test\data

what would you think startswith value to be...

a \

test
t
...etc


I will test this in detail tomorrow night...but right now I am writing code disconnected from the data.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
so this logic would ensure I have the proper \\   ?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you need to ever check for exactly "\\test\data". then this code would not work. You could, though, simply modify the query to have two conditions:

string root = Path.GetPathRoot(txtBox1.Text);
string slashRoot;

root = root.TrimEnd("\\");
slashRoot = root + "\\";

var docInfo = from d in sqlDb.Docs                   
              where d.Path.StartsWith(slashRoot) || d.Path == root;

Open in new window

Split them how you see fit. You're the boss in that regard  ; )
Thank you for both your help.
why would starting with root ..versus being equal to root..give a different value..

I need the value of the beginning of the server value supplied to be equal...given thats apart of a longer string.
I'm saying that in the database, if the column's value were exactly "\\test\data"--meaning nothing comes after "data"--and you wanted those values as well, then you'd need to use the 2nd code. If all of your values in the database always have something after "data", then the 1st code will suffice.
what if it didnt have data?
Like the column was NULL, or like the column's value was something other than "\\test\data"?
yes