本文整理汇总了C#中StringWriter.WriteLine方法的典型用法代码示例。如果您正苦于以下问题:C# StringWriter.WriteLine方法的具体用法?C# StringWriter.WriteLine怎么用?C# StringWriter.WriteLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringWriter
的用法示例。
在下文中一共展示了StringWriter.WriteLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteHeaders
/// <summary>
/// Write Header.
/// </summary>
/// <param name="request">Http Request.</param>
/// <param name="writer">String Writer.</param>
private static void WriteHeaders(HttpRequest request, StringWriter writer)
{
foreach (string key in request.Headers.AllKeys)
{
writer.WriteLine(string.Format("{0}: {1}", key, request.Headers[key]));
}
writer.WriteLine();
}
示例2: runTest
public bool runTest()
{
int iCountErrors = 0;
int iCountTestcases = 0;
String strTemp = String.Empty ;
Char[] cArr = new Char[10] ;
StringBuilder sb = new StringBuilder(40);
StringWriter sw = new StringWriter(sb);
StringReader sr;
iCountTestcases++;
bool[] bArr = new bool[]{ true,true,true,true,true,false,false,false,false,false};
try {
for(int i = 0 ; i < bArr.Length ; i++)
sw.WriteLine(bArr[i]);
sr = new StringReader(sw.GetStringBuilder().ToString());
for(int i = 0 ; i < bArr.Length ; i++) {
sr.Read(cArr, 0, bArr[i].ToString().Length+System.Environment.NewLine.Length);
if(new String(cArr, 0, bArr[i].ToString().Length) != bArr[i].ToString()) {
iCountErrors++;
printerr( "Error_298vc_"+i+"! Expected=="+bArr[i].ToString()+", got=="+new String(cArr));
}
}
} catch (Exception exc) {
iCountErrors++;
printerr( "Error_298yg! Unexpected exception thrown, exc=="+exc.ToString());
}
iCountTestcases++;
bArr = new bool[10000];
for(int i = 0 ; i < bArr.Length ; i++)
bArr[i] = Convert.ToBoolean(rand.Next(0,2));
try {
sb.Length = 0;
for(int i = 0 ; i < bArr.Length ; i++)
sw.WriteLine(bArr[i]);
sr = new StringReader(sw.GetStringBuilder().ToString());
for(int i = 0 ; i < bArr.Length ; i++) {
sr.Read(cArr, 0, bArr[i].ToString().Length+System.Environment.NewLine.Length);
if(new String(cArr, 0, bArr[i].ToString().Length) != bArr[i].ToString()) {
iCountErrors++;
printerr( "Error_57485_"+i+"! Expected=="+bArr[i].ToString()+", got=="+new String(cArr));
}
}
} catch (Exception exc) {
iCountErrors++;
printerr( "Error_43432! Unexpected exception thrown, exc=="+exc.ToString());
}
if ( iCountErrors == 0 )
{
Console.WriteLine( "paSs. iCountTestcases=="+iCountTestcases.ToString());
return true;
}
else
{
Console.WriteLine("FAiL! iCountErrors=="+iCountErrors.ToString() );
return false;
}
}
示例3: Response_Bug80944
static byte[] Response_Bug80944 (Socket socket)
{
StringWriter sw = new StringWriter ();
sw.WriteLine ("HTTP/1.1 200 OK");
sw.WriteLine ("Content-Type: text/plain; charset=UTF-8");
sw.WriteLine ("Content-Length: 4");
sw.WriteLine ();
sw.Write ("FINE");
return Encoding.UTF8.GetBytes (sw.ToString ());
}
示例4: Main
static void Main()
{
//string urlStr = "http://www.devbg.org/forum/index.php";
Console.WriteLine("input url:");
string urlStr = Console.ReadLine();
StringWriter sw = new StringWriter();
sw.WriteLine("[protocol] = {0}", GetProtocolPart(urlStr));
sw.WriteLine("[server] = {0}", GetServerPart(urlStr));
sw.Write("[resource] = {0}", GetResourcePart(urlStr));
Console.WriteLine(sw.ToString());
}
开发者ID:plamenshipkovenski,项目名称:CSharpPart2,代码行数:13,代码来源:extractProtocolServerResourceElementsFromURL.cs
示例5: ToString
public override string ToString()
{
StringWriter message = new StringWriter();
foreach (var item in storage)
message.WriteLine("{0}:\t{1}", item.Key, item.Value.ToString());
return message.ToString();
}
示例6: ToString
public override string ToString()
{
StringWriter message = new StringWriter();
foreach (Person obj in data)
message.WriteLine(obj.ToString());
return message.ToString();
}
示例7: Main
public static void Main(string[] arg) {
if (arg.Length < 1) throw new ArgumentException("Must pass one or two command line arguments.");
StringWriter sw = new StringWriter();
string s;
while ((s = Console.ReadLine()) != null) {
sw.WriteLine(s);
}
XmlDocument d = new XmlDocument();
d.LoadXml(sw.ToString());
object ret;
if (arg.Length == 1) {
ret = d.CreateNavigator().Evaluate(arg[0]);
} else if (arg.Length == 2 && arg[0] == "-expr") {
ret = d.CreateNavigator().Evaluate(arg[1]);
} else if (arg.Length == 2 && arg[0] == "-node") {
ret = d.SelectSingleNode(arg[1]);
} else {
throw new ArgumentException("Bad command line arguments.");
}
if (ret is XPathNodeIterator) {
XPathNodeIterator iter = (XPathNodeIterator)ret;
while (iter.MoveNext()) {
Console.WriteLine(iter.Current);
}
} else if (ret is XmlNode) {
Console.WriteLine(((XmlNode)ret).InnerXml);
} else {
Console.WriteLine(ret);
}
}
示例8: WriteStartLine
/// <summary>
/// Write Start Line.
/// </summary>
/// <param name="request">Http Request.</param>
/// <param name="writer">String Writer.</param>
private static void WriteStartLine(HttpRequest request, StringWriter writer)
{
const string SPACE = " ";
writer.Write(request.HttpMethod);
writer.Write(SPACE + request.Url);
writer.WriteLine(SPACE + request.ServerVariables["SERVER_PROTOCOL"]);
}
示例9: Main
public static void Main()
{
StringWriter writer = new StringWriter();
Stopwatch watch = new Stopwatch();
watch.Start();
for (int i = 0; i < iterations; i++)
writer.WriteLine("abcdefghijklmnopqurstuvxyz");
string str = writer.ToString();
watch.Stop();
Console.WriteLine(watch.ElapsedMilliseconds);
}
示例10: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
// Disable cache
Response.AddHeader("Pragma", "no-cache");
Response.AddHeader("Cache-Control", "no-store");
Response.AddHeader("Expires", "0");
// ping
ChatServer chatbox = Application["Chatbox"] as ChatServer;
Ping ping = chatbox.Ping(Context);
StringWriter writer = new StringWriter();
writer.WriteLine("id:{0},", ping.MyUser.Id);
writer.WriteLine("events:[");
for (int i=0; i<ping.Events.Count; i++)
{
Event evt = ping.Events[i];
writer.Write("[{0},\"{1}\",\"{2}\"]{3}", evt.User.Id, evt.Property.Name, evt.Property.Value, (i < ping.Events.Count - 1)? "," : "");
}
writer.WriteLine("]");
Response.Write(writer.ToString());
}
示例11: DownloadAsExcel
/// <summary>
///操作DataGrid DataTable導出到Excel.繁體OS,無亂碼問題.
/// </summary>
/// <param name="dg">DataTable</param>
/// <param name="ckID">CheckBox项的ID值 cbMail</param>
/// <param name="strFileName">含.xls後綴</param>
public static void DownloadAsExcel(DataGrid dg, DataSet ds, string ckID, string strFileName)
{
DataTable dt = GetSelectedTable(dg, ckID, ds);
if (dt == null)
{
dt = new DataTable();
}
try
{
StringWriter sw = new StringWriter();
string colstr = "";
foreach (DataColumn col in dt.Columns)
{
colstr += col.ColumnName + "\t";
}
sw.WriteLine(colstr);
foreach (DataRow row in dt.Rows)
{
colstr = "";
foreach (DataColumn col in dt.Columns)
{
colstr += row[col.ColumnName].ToString() + "\t";
}
sw.WriteLine(colstr);
}
sw.Close();
System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + strFileName + "");
System.Web.HttpContext.Current.Response.ContentType = "application/ms-excel";
System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default;
System.Web.HttpContext.Current.Response.Write(sw);
System.Web.HttpContext.Current.Response.End();
}
catch (Exception ex)
{
}
}
示例12: WriteBody
/// <summary>
/// Write Http Body.
/// </summary>
/// <param name="request">Http Request.</param>
/// <param name="writer">String Writer.</param>
private static void WriteBody(HttpRequest request, StringWriter writer)
{
if (request.InputStream.Position > 0)
{
request.InputStream.Position = 0;
}
var httpStream = new MemoryStream();
request.InputStream.CopyTo(httpStream);
httpStream.Position = 0;
using (var reader = new StreamReader(request.InputStream))
{
string body = reader.ReadToEnd();
writer.WriteLine(body);
}
}
示例13: run
public static string run(IEnumerable<ProductsDefine.modInfo> mods, bool newFormatOnly = false) {
//var logFn = @"q:\temp\EANewDeploy.log";
using (var wr = new StringWriter()) {
Parallel.ForEach(mods, new ParallelOptions() { MaxDegreeOfParallelism = 6 }, mod => {
StringBuilder sb = new StringBuilder();
//using (StringWriter wr = new StringWriter(err)) {
var ctx = new NewEATradosCtx(); string lastExId = null;
try {
sb.Length = 0;
NewEATradosLib.pageGroupStart(ctx);
foreach (var ex in mod.exs) {
lastExId = ex.Id;
StringBuilder err = new StringBuilder();
schools.exStatic meta = new exStatic() { title = ex.Title };
try {
string res;
if (ex.NewDataFormat) {
meta.url = ex.Id;
meta.format = ExFormat.rew;
res = CourseModel.Lib.Json(err, Machines.basicPath + @"rew\Web4\RwCourses\" + meta.url.Replace('/', '\\') + ".xml");
} else if (!newFormatOnly) {
meta.url = ex.Id.Split('/').Last();
meta.format = ExFormat.ea;
NewEATradosLib.pageStart(ctx, mod.crsId, meta.url, ex.Id + ".htm");
var cfg = new LMComLib.ConfigNewEA() {
ExerciseUrl = ex.Id,
CourseLang = urlToSrcLang(ex.Id),
Lang = mod.crsId == CourseIds.EnglishE ? "en-gb" : "en-gb",
courseId = mod.crsId
};
res = LowUtils.DownloadStr(string.Format("http://www.langmaster.com/comcz/framework/deployment/EANew-DeployGenerator.aspx?NewEACfg={0}", HttpUtility.UrlEncode(LowUtils.JSONEncode(cfg))));
} else
continue;
sb.Append(JsonConvert.SerializeObject(meta)); sb.Append("$$$"); sb.Append(res); sb.Append("$$$");
} finally {
if (err.Length > 0) lock (typeof(Exercise)) {
wr.WriteLine(">>>> " + ex.Id); wr.WriteLine(err.ToString());
}
}
}
if (!newFormatOnly || sb.Length > 0) {
var tradosRes = NewEATradosLib.pageGroupEnd(ctx); //JSON prelozenych retezcu
tradosRes[Langs.no] = sb.ToString(); //fake - pridej zdroj
EADeployLib.writeFiles(Machines.basicPath + @"rew\Web4\Schools\EAData\", mod.jsonId + ".json", tradosRes); //vypis zdroje i JSON prekladu
}
} catch (Exception exp) {
lock (typeof(Exercise)) { wr.WriteLine("******* ERROR: " + mod.path + "/" + lastExId + ": " + exp.Message); }
}
});
return wr.ToString();
}
}
示例14: lnkexportResources_Click
protected void lnkexportResources_Click(object sender, EventArgs e)
{
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
foreach (DataListItem li in UserList.Items)
{
GridView grd = (GridView)li.FindControl("ListUserTimeEntries");
ObjectDataSource ds = li.FindControl("TimeEntryData") as ObjectDataSource;
grd.DataSource = ds;
Label userlabel = (Label)li.FindControl("UserNameLabel");
Label DurationLabel = (Label)li.FindControl("TotalDurationLabel");
sw.Write("--------------------------------------------------------");
sw.WriteLine("\n");
sw.WriteLine("\n");
sw.NewLine = ("\n");
sw.NewLine = ("\n");
sw.Write("<table class='timeentry-edit' cellspacing='0' cellpadding='2' rules='all' border='0' style='border-width:0px;border-style:None;width:100%;border-collapse:collapse;'><tr class='grid-header' align='left'><th scope='col'>UserName</th><th scope='col'>Total Duration Worked</th> </tr><tr class='row1' style='border-style:None;'><td style='background-Color:#FFFFFF;'>" + userlabel.Text + "</td><td style='background-Color:#FFFFFF;'>" + DurationLabel.Text + "</td></tr></table>");
if (grd.Rows.Count >= 1)
{
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "ResourcesTimeSheet.xls"));
Response.ContentType = "application/ms-excel";
grd.AllowPaging = false;
grd.RenderBeginTag(htw);
int j = 1;
//This loop is used to apply stlye to cells based on particular row
foreach (GridViewRow gvrow in grd.Rows)
{
for (int k = 0; k < gvrow.Cells.Count; k++)
{
gvrow.Cells[k].Style.Add("background-Color", "#FFFFFF");
}
}
//grd.RenderControl(htw);
//style to format numbers to string
string style = @"<style> .textmode { mso-number-format:\@; } </style>";
grd.FooterRow.RenderControl(htw);
grd.RenderEndTag(htw);
grd.HeaderRow.Style.Add("background-color", "#FFFFFF");
grd.RenderControl(htw);
}
else
{
grd.DataSource = null;
}
}
sw.NewLine = ("\n");
sw.NewLine = ("\n");
sw.Close();
Response.Write(sw.ToString());
Response.End();
}
示例15: TestRunAllTestCases
public void TestRunAllTestCases()
{
StringWriter expected = new StringWriter();
expected.WriteLine("17 run, 0 failed");
StringWriter actual = new StringWriter();
Runner.Run(actual, new Result());
Assert.Equal(expected.ToString(), actual.ToString());
}