find child node title's text equel a value [closed] - c#

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
How do i find SiteMap.RootNode.ChildNames title's value equel 'test' in one line?
I don't write linq it doesn't work.
protected SiteMapNodeCollection getParentNodeTitle()
{
SiteMap.RootNode.ChildNames
}

This should do the trick:
var mySiteMap = new SiteMap();
/* Lots of code for populating your SiteMap here */
var nodeTitledTest = mySiteMap.RootNode.ChildNodes.Where(x => x.Title == "test").FirstOrDefault();
This will return the first node with a title equal to "test" or null if no such node could be found.

Related

XML all elements to list [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
My problem is with Xml file, which to look :
This isn't work.
IEnumerable<XElement> stepsList = doc.Elements();
XML file
<OneGoal>
<Goal>100000</Goal>
<StepOne>ewewewe</StepOne>
<StepTwo>wee</StepTwo>
<StepThree>MY</StepThree>
<StepFour>wwwww</StepFour>
<StepFive>ddddw</StepFive>
<StepSix>fcd</StepSix>
<StepSeven>blblblfl</StepSeven>
<StepEight>z dwadddddsssssssssssss</StepEight>
<StepNine>radwds</StepNine>
<StepTen>
blblblblblblb
</StepTen>
<DateDay>18</DateDay>
<DateMonth>7</DateMonth>
<DateYear>2019</DateYear>
</OneGoal>
I want all elements to IEnumberable . Earlier all elements have name 'step'.
How about converting your flat xml to Dictionary<string,string>?
var dict = XDocument.Parse(xml)
.Element("OneGoal")
.Elements()
.ToDictionary(e => e.Name.LocalName, e => e.Value);
Console.WriteLine(dict["StepOne"]);
Use XDocument to load from a file or parse from a string.
var stepList = doc.Descendants();

Getting value by name from OrderedDictionary [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I am looking for something like PHP's associative arrays that supports nesting too. For instance, I am creating a Dictionary Object like following:
System.Collections.Specialized.OrderedDictionary userRoles = new System.Collections.Specialized.OrderedDictionary();
userRoles["UserId"] = "120202";
userRoles["UserName"] = "Jhon Doe";
// 2D array Like
userRoles["UserRoles"][0] = "CAN_EDIT_LIST";
userRoles["UserRoles"][1] = "CAN_EDIT_PAGE";
Then I would like to access them by KeyNames instead of index values. Is it possible?
OrderedDictionary uses objects for both keys and values.
To achieve nesting, just set the value to be another dictionary:
userRoles["UserRoles"] = new Dictionary();
Then you can use:
((Dictionary())userRoles["UserRoles"])["MyKey"] = "My Value";

Javascript regexp.test() .NET equivalent [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
How can I do the following in C# :
var re = /^\d{4}(\/\d{2}){2} \d{2}(:\d{2}){2}$/;
re.test('2013/03/05 15:22:00'); // returns true
You can use the Regex.IsMatch instead (docs).
Regex.IsMatch("2013/03/05 15:22:00", #"^\d{4}(\/\d{2}){2} \d{2}(:\d{2}){2}$"); // true if match
The below code should get you where you want to be.
Regex rx = new Regex(#"^\d{4}(\/\d{2}){2} \d{2}(:\d{2}){2}$");
String test = "2013/03/05 15:22:00";
if (rx.IsMatch(test))
{
//Test String matches
}
else
{
//Test String does not match
}

removing stop words from a specific string using c# [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have an array of words and I want to remove them from an input string, could anyone tell me what is the better way to conduct this task?
This should work
string[] arrToCheck = new string[] { "try ", "yourself", "before " };
string input = "Did you try this yourself before asking";
foreach (string word in arrToCheck )
{
input = input.Replace(word, "");
}
MessageBox.Show("result is "+input);
input variable will now have a string which does not have those words in your array.

INSTR equivalent into c# string.indexof() how do i use [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I have if else condition in one function in oracle
i need to convert that into c# code please help.
IF INSTR( pString, pSeparator, -1, 1) != ( LENGTH( RTRIM( pString )) - LENGTH( pSeparator ) + 1 )
THEN
-- There isn't one at the end so add it
l_Return := pString || pSeparator;
--DBMS_OUTPUT.PUT_LINE('Did not find seperator - ADDING');
In this case you can use string.EndsWith() instead, that's exactly what you are trying to check:
if(!pString.EndsWith(pSeparator))
{
//There isn't one at the end so add it
}

Categories