c# - 替换一个数组中包含在另一个数组中的值,而不遍历每条记录
问题描述
我正在通过抓取音乐节的网站艺术家页面来创建 Spotify 播放列表生成器。我能够返回所有艺术家姓名,但其中一些没有链接到 Spotify 搜索词,例如:
Festival Artist Name: "Slash and..."
Spotify Search Term: "Slash"
我创建了一个名为EdgeCases
:
public int EdgeCasesID { get; set; }
public int FestivalID { get; set; }
public string ComparableString { get; set; }
public string SearchTerm { get; set; }
public bool Skip { get; set; }
它表示替换/跳过/搜索与 Spotify 搜索词不匹配的艺术家所需的所有数据。
我目前拥有的代码将所有边缘情况与从网页中提取的所有艺术家进行比较;我只想帮助如何减少代码+比较
foreach (string artist in artistNames)
{
bool skipArtist = false;
SearchItem searchItem = null;
// Check if any of those artists exist in the UnfoundArtists database
// More or less check if the name is different on Spotify or if they are even on Spotify
foreach (EdgeCase unfoundArtist in EdgeCases)
{
// If the download artist page contains the a specific name
// e.g if 'slash & the conspirators' contains 'slash'
if (artist.Trim().Contains(unfoundArtist.ComparableString))
{
// If so, check if the artist is on Spotify
if (unfoundArtist.ToSearch)
{
// search using SearchTerm
}
// This case is if the artist is on the page but not on Spotify
skipArtist = true;
}
else
{
// Search the artist if there is no edge case - different Spotify
// name/on Spotify at all etc
searchItem = _api.SearchItems(artist.Trim(), SearchType.Artist, limit: 1);
}
}
}
解决方案
推荐阅读
- reactjs - ReactJs StyledComponent 和 ClassName
- git - 我的拉取请求有一个我没有写的代码
- node.js - 节点进程通信
- swift - 使用 https://cocoapods.org/pods/SQLite.swift 附加两个 sqlite 数据库的问题
- reactjs - 来自 Geolocation API 的国家/地区
- docker - 无法访问部署到 kubernetes 的容器化 asp.core web api?
- sockets - 如何使用 PORT 命令获取 IPv6 地址
- scala - Scala中的字符串插值
- angular - 为什么Angular Flex Layout默认为小窗口视图?
- typescript - 模拟类型,如 Typescript 中的“{[id: string]: Details}|null”