다음 문제가 있습니다.string.Remove doesnt work
ive는 jpg 파일에 대한 추가 링크로 Google 이미지 검색을 사용하는 programm로 작성되었습니다. 하지만 링크 앞에 나는 내가 가질 수없는 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);
}
나는 제거 및 trimstart를 시도했지만 그 중 아무 것도 작동하지 않으며 실패를 파악할 수 없습니다.
나는
for (int i = 0; i < results.Count(); i++)
{
if (results[i] != null)
{
results[i] = results[i].Substring(15);
Console.Write(results[i]+"\n");
}
}
당신은 당신이 문자열을 사용할 수있는 15 자 덤프 할 것을 알고 있기 때문에. –
대부분의 코드는 실제로 귀하의 질문과 관련이 없으며 사용하지도 않는 변수가 있습니다. (왜'ToCharArray '를 호출하는 것입니까?) –
내 실패가 MatchCollection에 있을지 확신 할 수 없었습니다 –