C\#키 워드 를 차단 하 는 실현 방법
2569 단어 C#키 워드 를 가리기
안에 있 는 내용 은 한 줄 이 하 나 를 대표 합 니 다.저 는 줄 에 따라 차단 할 키 워드 를 반복 해서 읽 기 때 문 입 니 다.그리고*번호 로 키 워드 를 차단 합 니 다.
예 를 들 어 포럼 에서'진흙 말'을 수출 하 는 것 은 비교적 민감 한 화제,이름 과 관련 되 고 홍보 가 비교적 뜨 거 운 사이트 에서 모두 허용 되 지 않 기 때문에 여 기 는'**'만 표 시 됩 니 다 여기 코드 아래 에 제 가 나 왔 습 니 다.주석 이 상세 합 니 다.모 르 는 것 은 댓 글로 저 에 게 물 어보 세 요.블 로 거들 이 매일 조금씩 발전 하 기 를 바 랍 니 다.
/// <summary>
/// ( , "***" )
/// </summary>
/// <param name="strText"> </param>
/// <returns> </returns>
public static string CheckKeyword(string strText)
{
IList<string> list = new List<string>(); //
string strpath = System.Web.HttpContext.Current.Server.MapPath("function/keyword.txt"); //
int a =strpath.LastIndexOf("IFSns");
int b =strpath.IndexOf("function");
string m = strpath.Substring(a+5, b - a - 6);
string PathTxt = strpath.Replace(m, ""); //
FileStream fs = new FileStream(PathTxt, FileMode.Open, FileAccess.Read); // txt ,
StreamReader reader = new StreamReader(fs, Encoding.Default); //
string strLine = reader.ReadLine();
while (strLine!=null&&strLine.Length != 0) //
{
list.Add(strLine.Trim().Replace(" ","")); // , , string
strLine = reader.ReadLine(); // ,
}
fs.Close(); //
foreach (string str in list) //
{
if (strText.Contains(str))
{
int lg = str.Length;
string sg = "";
for (int i = 0; i < lg; i++)
{
sg+="*";
}
strText = strText.Replace(str, sg); // txt , "***"
}
}
return strText;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
WebView2를 Visual Studio 2017 Express에서 사용할 수 있을 때까지Evergreen .Net Framework SDK 4.8 VisualStudio2017에서 NuGet을 사용하기 때문에 패키지 관리 방법을 packages.config 대신 PackageReference를 사용해야...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.