删除不完整的URL

2024-09-30 06:12:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个包含坏网址的文本文件

 http images5fanpopcomimagephotos29000000ichigowallpaperkurosakiichigo290694271024768jpg

以及

 https smediacacheak0pinimgcomoriginals1219ed1219ed717fc2bfce372759bba2fe1cfegif 

是的。我想删除这些长字符串后面的http或https。你知道吗

有人能提出解决办法吗?你知道吗


Tags: 字符串httpshttp网址文本文件解决办法smediacacheak0pinimgcomoriginals1219ed1219ed717fc2bfce372759bba2fe1cfegifimages5fanpopcomimagephotos29000000ichigowallpaperkurosakiichigo290694271024768jpg
1条回答
网友
1楼 · 发布于 2024-09-30 06:12:38

您可以在每一行中搜索http或https,如果该行长度超过X个字符(例如40个字符),并且其中没有“/”和/或“.”,请删除。你知道吗

System.IO.StringReader strReader = new System.IO.StringReader(input);
string line;
string output;
while ((line = strReader.ReadLine()) != null)
{
  if(line.IndexOf("http") == 0)
  {
    if( (line.Length >40) && ((line.Contains('.') == false) || (line.Contains('/') == false)) )
      {
        add = false;
      } else {
        add = true;
      }
    } else {
      add = true
    }
  if(add)   output += line + "\r\n";
}

相关问题 更多 >

    热门问题