如何检查特定字符串是否存在于字节数组中?
How to check whether a particular string is present in a byte array?
var PDF = new ActionAsPdf("TestReport", null)
{
FileName = "TestFile.pdf",
PageOrientation = Rotativa.Options.Orientation.Landscape,
PageMargins = { Left = 1, Right = 1 }
};
byte[] PDFData = PDF.BuildPdf(ControllerContext);
是否可以检查 'PDFData' 中的字符串(例如 "Daily Task")?
请指导我。谢谢!
尝试将 byte
数组转换为 string
:
var str = System.Text.Encoding.Default.GetString(PDFData);
var isContains = str.Contains("Daily Task");
一个例子:
string dailyTask = " Daily Task ";
byte[] PDFData = Encoding.ASCII.GetBytes(dailyTask);
var str = System.Text.Encoding.Default.GetString(PDFData);
var isContains = str.Contains("Daily Task");
Console.WriteLine(isContains);
var PDF = new ActionAsPdf("TestReport", null)
{
FileName = "TestFile.pdf",
PageOrientation = Rotativa.Options.Orientation.Landscape,
PageMargins = { Left = 1, Right = 1 }
};
byte[] PDFData = PDF.BuildPdf(ControllerContext);
是否可以检查 'PDFData' 中的字符串(例如 "Daily Task")? 请指导我。谢谢!
尝试将 byte
数组转换为 string
:
var str = System.Text.Encoding.Default.GetString(PDFData);
var isContains = str.Contains("Daily Task");
一个例子:
string dailyTask = " Daily Task ";
byte[] PDFData = Encoding.ASCII.GetBytes(dailyTask);
var str = System.Text.Encoding.Default.GetString(PDFData);
var isContains = str.Contains("Daily Task");
Console.WriteLine(isContains);