gpt4 book ai didi

c# - string.Remove 不起作用

转载 作者:太空狗 更新时间:2023-10-29 22:03:37 25 4
gpt4 key购买 nike

<分区>

我有以下问题:

我写了一个程序,它使用谷歌图片搜索来提取 jpg 文件的链接。但是在链接前面,我有一个 15 个字符长的字符串,我无法将其删除。

    public const int resolution = 1920;
public const int DEFAULTIMGCOUNT = 40;

public void getimages(string searchpatt)
{
string blub = "http://images.google.com/images?q=" + searchpatt + "&biw=" + resolution;
WebClient client = new WebClient();

string html = client.DownloadString(blub); //Downloading the gooogle page;
MatchCollection mc = Regex.Matches(html,
@"(https?:)?//?[^'<>]+?\.(jpg|jpeg|gif|png)");

int mccount = 0; // Keep track of imgurls
string[] results = new string[DEFAULTIMGCOUNT]; // String Array to place the Urls

foreach (Match m in mc) //put matches in string array
{
results[mccount] = m.Value;
mccount++;
}

string remove = "/imgres?imgurl=";
char[] removetochar = remove.ToCharArray();

foreach (string s in results)
{
if (s != null)
{
s.Remove(0, 15);
Console.WriteLine(s+"\n");
}
else { }
}
// Console.Write(html);


}

我试过 remove 和 trimstart 但它们都不起作用,我无法弄清楚我的失败。

我是这样解决的

        for (int i = 0; i < results.Count(); i++)
{
if (results[i] != null)
{
results[i] = results[i].Substring(15);
Console.Write(results[i]+"\n");
}
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com