Robb Hill
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\f igure\this \out\filec onclusion. 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
For example they might type
\\RootShare\Par4\
I might have this stored in the database as such as varchar.
\\RootShare\Par4\help\me\f
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\
or
\\RootShare\Par444\Par4 (incorrect)
or
\\RootShare\Par4\par4 (incorrect
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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
ASKER
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.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
so this logic would ensure I have the proper \\ ?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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;
Split them how you see fit. You're the boss in that regard ; )
ASKER
Thank you for both your help.
ASKER
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 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.
ASKER
what if it didnt have data?
Like the column was NULL, or like the column's value was something other than "\\test\data"?
ASKER
yes
ASKER
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