当前位置: 首页>>代码示例>>C#>>正文


C# StreamWriter.ToString方法代码示例

本文整理汇总了C#中System.IO.StreamWriter.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# StreamWriter.ToString方法的具体用法?C# StreamWriter.ToString怎么用?C# StreamWriter.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.StreamWriter的用法示例。


在下文中一共展示了StreamWriter.ToString方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Dump

 public static string Dump(this object element)
 {
     var memoryStream = new MemoryStream();
     TextWriter textWriter = new StreamWriter(memoryStream);
     ObjectDumper.Write(element, 3, textWriter);
     return textWriter.ToString();
 }
开发者ID:khebbie,项目名称:Dynamicpad,代码行数:7,代码来源:ObjectDumpExtensions.cs

示例2: GetToLocalHtml1

        /**
         HTML保存到本地
        **/
        public static void GetToLocalHtml1()
        {
            var url = "http://stock.10jqka.com.cn/fincalendar.shtml#2015-12-18";
            string strBuff = "";//定义文本字符串,用来保存下载的html  
            int byteRead = 0;

            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
            HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
            //若成功取得网页的内容,则以System.IO.Stream形式返回,若失败则产生ProtoclViolationException错 误。在此正确的做法应将以下的代码放到一个try块中处理。这里简单处理   
            Stream reader = webResponse.GetResponseStream();
            ///返回的内容是Stream形式的,所以可以利用StreamReader类获取GetResponseStream的内容,并以StreamReader类的Read方法依次读取网页源程序代码每一行的内容,直至行尾(读取的编码格式:UTF8)  
            StreamReader respStreamReader = new StreamReader(reader, Encoding.UTF8);

            ///分段,分批次获取网页源码  
            char[] cbuffer = new char[1024];
            byteRead = respStreamReader.Read(cbuffer, 0, 256);
            string htm = "";           
            while (byteRead != 0)
            {
                string strResp = new string(cbuffer, 0, byteRead);
                strBuff = strBuff + strResp;
                byteRead = respStreamReader.Read(cbuffer, 0, 256);
            }
            using (StreamWriter sw = new StreamWriter("d:\\GetHtml.html"))//将获取的内容写入文本  
            {
                htm = sw.ToString();//测试StreamWriter流的输出状态,非必须  
                sw.Write(strBuff);
            }
        }
开发者ID:wsjiabao,项目名称:autodz,代码行数:32,代码来源:HtmlUtl.cs

示例3: Minify

 public string Minify(TextReader reader, StreamWriter writer)
 {
     sb = writer;
     tr = reader;
     theA = '\n';
     theB = 0;
     theLookahead = EOF;
     cssmin();
     return sb.ToString();
 }
开发者ID:thilehoffer,项目名称:CSM,代码行数:10,代码来源:CssMin.cs

示例4: Guardar

 public void Guardar()
 {
     try
     {
         GuardarCadenaConexion(Properties.RutaBaseDatos);
         using (var sw = new StreamWriter(Application.StartupPath + ConfigurationManager.AppSettings["SettingsFolder"] + ConfigurationManager.AppSettings["SettingsName"]))
         {
             XmlSerializer serializer = new XmlSerializer(typeof(SettingsApplicationProperties));
             serializer.Serialize(sw, Properties);
             sw.ToString();
         }
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
开发者ID:eduardo18razo,项目名称:SmarQuilaChiles,代码行数:17,代码来源:SettingsApplication.cs

示例5: GuardarImpresoras

        public static void GuardarImpresoras(List<Impresora> impresoras)
        {
            try
            {
                if (!Directory.Exists(_folderSettings))
                    Directory.CreateDirectory(_folderSettings);

                string file = _folderSettings + ConfigurationManager.AppSettings["FilePrinter"] + ".xml";
                using (var sw = new StreamWriter(file))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(List<Impresora>));
                    serializer.Serialize(sw, impresoras);
                    sw.ToString();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
开发者ID:eduardo18razo,项目名称:SmarQuilaChiles,代码行数:20,代码来源:Impresoras.cs

示例6: GenerarProperties

        public void GenerarProperties()
        {
            try
            {
                Properties.EsServidor = false;
                Properties.PrimeraArranque = true;
                Properties.TecladoPantalla = false;
                Properties.SplasImage = null;

                using (var sw = new StreamWriter(Application.StartupPath + ConfigurationManager.AppSettings["SettingsFolder"] + ConfigurationManager.AppSettings["SettingsName"]))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(SettingsApplicationProperties));
                    serializer.Serialize(sw, Properties);
                    sw.ToString();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

        }
开发者ID:eduardo18razo,项目名称:SmarQuilaChiles,代码行数:22,代码来源:SettingsApplication.cs

示例7: SaveToFile

        public void SaveToFile(string path)
        {
            try {
                var serializer = new XmlSerializer (typeof(AppSettings));

                using (var file = new FileStream(path, FileMode.Create)) {
                    using (StreamWriter stream = new StreamWriter(file, Encoding.UTF8)) {
                        Console.WriteLine (stream.ToString ());
                        serializer.Serialize (stream, this);

                    }

                    file.Close ();
                }

                Console.WriteLine ("Settings save to: " + path + " ");

            } catch (Exception e) {
                Console.WriteLine ("Can`t save settings: " + path + " " + e.Message);

            }
        }
开发者ID:rastabaddon,项目名称:QCCTV,代码行数:22,代码来源:AppSettings.cs

示例8: GetToLocalHtml

        /**
         * 保存到本地HTML
         **/        
        public static string GetToLocalHtml(string url, string exportPath)
        {
            string htm = "";
            try
            {
                WebClient webClient = new WebClient();
                webClient.Credentials = CredentialCache.DefaultCredentials;//获取或设置用于向Internet资源的请求进行身份验证的网络凭据  
                Byte[] pageData = webClient.DownloadData(url);
                string pageHtml = Encoding.Default.GetString(pageData);  //如果获取网站页面采用的是GB2312,则使用这句         
                //string pageHtml = Encoding.UTF8.GetString(pageData); //如果获取网站页面采用的是UTF-8,则使用这句  
                //string pageHtml = Encoding.GetEncoding("GBK").GetString(pageData); //如果获取网站页面采用的是UTF-8,则使用这句  
                using (StreamWriter sw = new StreamWriter(exportPath))//将获取的内容写入文本  
                {
                    htm = sw.ToString();//测试StreamWriter流的输出状态,非必须  
                    sw.Write(pageHtml);
                }
            }
            catch (WebException webEx)
            {
                Console.WriteLine(webEx.Message);
            }

            return exportPath;
        }
开发者ID:wsjiabao,项目名称:autodz,代码行数:27,代码来源:HtmlUtl.cs

示例9: CombineScript

        public string CombineScript(StreamWriter strWriter)
        {
            //Write all usings
            strWriter.WriteLine(UsingsText);
            Usings.ForEach(u => strWriter.WriteLine(u));
            //Write class header
            strWriter.WriteLine(ClassBeginText);
            strWriter.WriteLine("public class " + ClassName + " : UniBehaviour {");
            //Write variables
            Variables.ForEach(v =>
            {
                //Write var data
                strWriter.WriteLine(TabSpaces + VarText + "%" +
                    "{\"acceessModifier\":\"" + v.VarAccessModifier + "\"," +
                    "\"type\":\"" + v.VarType + "\"," +
                    "\"name\":\"" + v.VarName + "\"," +
                    "\"value\":\"" + v.VarValue + "\"}");
                //Write var code
                strWriter.WriteLine(TabSpaces + v.VarAccessModifier + " " + v.VarType + " " + v.VarName + " = " + v.VarValue + ";");
            });
            //Write events (they forming string with line end by themselves)
            Events.ForEach(e => { e.CombineScript(strWriter); });
            //Write class end
            strWriter.WriteLine(ClassEndText);
            strWriter.WriteLine("}");

            string result = strWriter.ToString();
            strWriter.Close();

            return result;
        }
开发者ID:bL00RiSe,项目名称:UniMaker,代码行数:31,代码来源:UniEditorAbstract.cs

示例10: Main

        static void Main(string[] args)
        {
            TextReader tr;
            TextWriter tw;
            string defaultEndpoint = "http://localhost:53033/validate/html";
            string defaultReadfile = @"C:\Users\Administrator\Documents\GitHub\LeanKit.Utilities\Validation.TestUtility\test.txt";
            string defaultWritefile = @"C:\Users\Administrator\Documents\GitHub\LeanKit.Utilities\Validation.TestUtility\test2.txt";
            string ep;
            string connectionString = null;
            string query = null;


            //handle options
            var options = new Options();
            if (CommandLine.Parser.Default.ParseArguments(args, options))
            {
                if (options.inputFile != null)
                {
                    try
                    {
                        tr = new StreamReader(options.inputFile);
                        Console.WriteLine(String.Format("Input file is set as {0}", tr.ToString()));
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(@"Cannot locate this file. Setting input at default value.");
                        tr = new StreamReader(defaultReadfile);

                    }
                }
                else
                {

                    tr = new StreamReader(defaultReadfile);
                    Console.WriteLine(@"Input file is set as C:\Users\Administrator\Documents\GitHub\LeanKit.Utilities\Validation.TestUtility\test.txt");

                }
                if (options.outputFile != null)
                {
                    tw = new StreamWriter(options.outputFile);
                    Console.WriteLine(String.Format("Output file is set as {0}", tw.ToString()));
                }
                else
                {
                    tw = new StreamWriter(defaultWritefile);
                    Console.WriteLine(defaultWritefile);
                }
                if (options.url != null)
                {
                    string url = options.url;
                    Console.WriteLine(String.Format(@"The url which will be scrapped is {0}", url));
                }
                if (options.endpoint != null)
                {
                    ep = options.endpoint;
                }
                else
                {

                    ep = defaultEndpoint;
                    Console.WriteLine(String.Format(@"The api endpoint set is{0}", defaultEndpoint));
                }
                //Check and set database variables
                if (options.dbserver != null && options.dbname != null && options.dbuser != null && options.dbpassword != null && options.dbquery != null)
                {
                    connectionString = String.Format(@"Data Source = {0}; Initial Catalog ={1}; Persist Security Info = true; User ID={2};Password={3}", options.dbserver, options.dbname, options.dbuser, options.dbpassword);
                    query = options.dbquery;
                }

            }
            else
            {
                string url;
                tr = new StreamReader(defaultReadfile);
                tw = new StreamWriter(defaultWritefile);
                ep = defaultEndpoint;
                connectionString = null;

            }

            ////////////////////////////////////////

            if (options.url != null)        //if scraping a url
            {

                Task<String> resp = scraper(options.url);

                if (resp.Result != null)
                {
                    Task<String> apiresp = ApiRequest(resp.Result, ep);
                    if (apiresp.Result != null)
                    {
                        string s = apiresp.Result;
                        tw.WriteLine("\tResult:\t{0}\n", s);
                    }
                    else
                    {
                        tw.WriteLine("\tResult: Format accepted\n");
                    }
                }
//.........这里部分代码省略.........
开发者ID:chrisgundersen,项目名称:LeanKit.Utilities,代码行数:101,代码来源:TestUtility.cs


注:本文中的System.IO.StreamWriter.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。