Check if string values appear more than once in document [closed] - c#

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a document (xml) where each line has a format like this
<Field ID="{475c2610-c157-4b91-9e2d-6855031b3538}" Name="FullName" DisplayName="Full name" Type="Text" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="FullName" ColName="nvarchar6" Required="FALSE" Hidden="TRUE" ReadOnly="FALSE" PITarget="" PrimaryPITarget="" PIAttribute="" PrimaryPIAttribute="" Aggregation="" Node="" />
The properties ColName="<>" and ID="{<>}" are supposed to be unique for every line that exists in the document.
How can I loop through each line and and see if the values inside ColName and ID appears more than once(preferrably though C#)?

Treating it like code golf... to get duplicate elements:
var duplicateElements = XDocument.Load(pathToDocument).Root.Elements()
.GroupBy(el => String.Format("{0}|{1}", el.Attribute("ID").Value, el.Attribute("ColName").Value)))
.Where((val, e) => val.Count() > 1);

Related

How to align content from a lump of data from sql to web? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I have a text in SQL like: "I want to eat. I'm hungry."
I use ASP.NET MVC to get data from database:
#Model.content
#Model.content is "I want to eat. I'm hungry."
I want to format text to display, for example, it might come down the line:
I want to eat.
I'm hungry.
Since, you don't prefer saving "\n" in the database, you can just split the entire into an array and loop through each item to display it with breaks. use Split
Something like:
#foreach (var item in Model.content.Split(".")) { #item <br /> }

i want add value number to first element of of text box [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
txtpayAmount.Text = gblFunction.ConvertTwoDecimal(
txtpayAmount.Text,
btn.Tag.ToString(),
txtpayAmount.SelectedText.Length);
txtpayAmount.Focus();
txtpayAmount.SelectionStart = txtpayAmount.Text.Length;
This is my code , am trying to add the value of button to textbox but its adding as last element of textbox.I want to add as first element
If I understand correctly (your question is confusing), you want prepend the text in a textbox.
If you want to do so you can do a txtBox.Value = 'ValueToPrepend' + txtBox.Value;

How to parse this XML to get the count on ASP.NET? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I need a help to parse the below XML, What I wanted to do is the count of the entry id, below XML has 5 for entry id's. So What code should I write on C# to get the count from this XML? Thanks in advance
<entry_list version="1.0">
<entry id="cipher[1]">...</entry>
<entry id="cipher[2]">...</entry>
<entry id="cypher">...</entry>
<entry id="substitution cipher">...</entry>
<entry id="transposition cipher">...</entry>
</entry_list>
Try this:
var xdoc = XDocument.Load(#"FileToLoad.xml");
var count = xdoc.Descendants("entry").Count(); // 5

C# XML Get to Attribute and output an element [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I've got this piece of XML, and I just need the value of an specific key. Like the sting input is "c4ca4238a0b923820dcc509a6f75849b" and it just needs to read: "Lorem Ispum".
<data>
<key id="c4ca4238a0b923820dcc509a6f75849b" alt-id="1">
<value>Lorem Ispum</value>
</key>
<key id="c81e728d9d4c2f636f067f89cc14862c" alt-id="2">
<value>Dolor Sit Amet</value>
</key>
</data>
This might do the trick for you
XDocument xdc = XDocument.Load("YourXMLFile");
var SomeValue = xdc.Descendants("key")
.Where(x => x.Attribute("id").Value == "c4ca4238a0b923820dcc509a6f75849b")
.Descendants("value")
.FirstOrDefault()
.Value;

Input string was not in a correct format in gridview [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am updating the values in grid view. if i am updating the noofdays it will showing Input string was not in a correct and how to give me some suggestion.
and i have other question when the employee apply leave before week it will take the data else it will show the message.
how to write it logic.
code behind
leaveUpdateRow.NoOfDays = Convert.ToInt32(((TextBox)(row.Cells[4].Controls[0])).Text);
ASPX
<asp:BoundField DataField="NoOfDays" HeaderText="Leave Period"></asp:BoundField>
Try this
leaveUpdateRow.NoOfDays = Convert.ToInt32(((TextBox)(row.Cells[4].Controls[0])).Text) == NULL ? 0 :Convert.ToInt32(((TextBox)(row.Cells[4].Controls[0])).Text);
Try it
please check the value is integer before convert the values.
Use string.IsNullOrEmpty
leaveUpdateRow.NoOfDays=string.IsNullOrEmpty(((TextBox)(row.Cells[4].Controls[0])).Text)?0:Convert.ToInt32(((TextBox)(row.Cells[4].Controls[0])).Text);

Categories