将HTML列表的内容传输到文本(Transferring contents of HTML list to text)
如何才能做到这一点? .InnerText属性(当在包含
div
元素上使用时)仅给我html。 是否有可能遍历所有包含的li
元素并提取它们的值?How can this be done? The .InnerText Property (when used on the containing
div
element) is giving me the html only. Is it possible to iterate through all theli
elements contained and extract their values?
原文:https://stackoverflow.com/questions/4620945
更新时间:2022-09-06 21:09
最满意答案
预期结果是什么? 很容易输出你想要的结果。 只需使用
foreach
:foreach(var dup in dups) { Console.WriteLine(String.Format("EmployeeName - {0}", dup.Key)); foreach(EmployeeModel x in dup) Console.WriteLine(String.Format("placeString:{0} timeString:{1}", x.Place, x.Time));}); }
What is the expected result? It's easy to output your desired result. Just use a
foreach
:foreach(var dup in dups) { Console.WriteLine(String.Format("EmployeeName - {0}", dup.Key)); foreach(EmployeeModel x in dup) Console.WriteLine(String.Format("placeString:{0} timeString:{1}", x.Place, x.Time));}); }
相关问答
更多-
var duplicates = allMyObjects.GroupBy(a => a.MyString) .Where(a => a.Count() > 1) .SelectMany(g=>g) .ToList(); var duplicates = allMyObjects.GroupBy(a => a.MyString) .Where(a => a.Count() > 1) .SelectMany(g=>g) .ToList();
-
您可以使用“group by”+“orderby”。 有关详细信息,请参见LINQ 101 var list = new List
{"a", "b", "a", "c", "a", "b"}; var q = from x in list group x by x into g let count = g.Count() orderby count descending select new {Value = g.Key, C ... -
C#LINQ在列表中找到重复项(C# LINQ find duplicates in List)[2021-08-01]
解决问题的最简单的方法是根据它们的值对元素进行分组,然后选择组中的代表,如果组中有多个元素。 在linq中,这意味着: var query = lst.GroupBy(x=>x) .Where(g=>g.Count()>1) .Select(y=>y.Key) .ToList(); 如果您想知道重复元素的次数,可以使用: var query = lst.GroupBy(x=>x) .Where( ... -
检查列表中的唯一值,然后递增重复项c#Linq(Check for unique values in a list, and then increment the duplicates c# Linq)[2022-08-27]
您可以使用Select项目索引的重载: ListresultList = list .GroupBy(s => s) .SelectMany(g => g .Select((s, index) => $"{s}{(index == 0 ? "" : $" ({index})")}")) .ToList(); You can use the overload of Select that projects the index: List ... -
如果EndPointParameters是List
(“从列表中删除多个对象”),您可以尝试RemoveAll而不是Linq : // Remove the not required parameters foreach (EndPoint endPoint in endPoints) { // Remove all items from EndPointParameters that both // 1. Implement IEndPointParamMapCustom ... -
您可以使用预选列表列出要选择的名称和字段 var lookups = new Dictionary
> { {"M1", x => x.M1 }, {"M2", x => x.M2 }, {"M3", x => x.M3 }, {"M4", x => x.M4 }, {"M5", x => x.M5 }, }; 然后你就可以做到 var mRes = dlookups.Select(x => new Results { ... -
如何使用LINQ从具有重复项的列表中获取第N个最大元素?(How do I get the Nth largest element from a list with duplicates, using LINQ?)[2023-06-22]
要使所有项目的集合等于第N个最大项目,您需要对项目进行分组,对组进行排序,然后按组大小递减N,同时N为正。 当N达到零时,您已经击中了包含第N个最大项目的组。 public static IEnumerableFoo (this IEnumerable source, int n) { return source.GroupBy(x => x) .OrderByDescending(group => group.Key) .SkipWhile(gro ... -
对于你明确的“忽略空格”的情况,你可以简单地打电话 var results = result.GroupBy(c => c.Name.Replace(" ", ""))... 但是,在您需要灵活性的一般情况下,我会建立一个IEqualityComparer
类库,以便在您的分组中使用。 例如,这应该在“忽略空间”的情况下做同样的事情: public class CompanyNameIgnoringSpaces : IEqualityComparer { publ ... -
我会用C#编写它,但希望你能把它转换成VB。 它不使用join并且是O(n log n),我假设你有List
: lst.Sort(); //O(nlogn) part. var duplicatedItems = lst.Skip(1).Where((x,index)=>x.ID == lst[index].ID); The project is behind, I just hacked it together like this: ' For each outcome, if it ... -
预期结果是什么? 很容易输出你想要的结果。 只需使用foreach : foreach(var dup in dups) { Console.WriteLine(String.Format("EmployeeName - {0}", dup.Key)); foreach(EmployeeModel x in dup) Console.WriteLine(String.Format("placeString:{0} timeString:{1}", x.Place, x.Tim ...