stringbuilder

What does ----s mean in the context of StringBuilder.ToString()?

北城以北 提交于 2019-11-28 22:28:40
The Reference Source page for stringbuilder.cs has this comment in the ToString method: if (chunk.m_ChunkLength > 0) { // Copy these into local variables so that they // are stable even in the presence of ----s (hackers might do this) char[] sourceArray = chunk.m_ChunkChars; int chunkOffset = chunk.m_ChunkOffset; int chunkLength = chunk.m_ChunkLength; What does this mean? Is ----s something a malicious user might insert into a string to be formatted? In the CoreCLR repository you have a fuller quote: Copy these into local variables so that they are stable even in the presence of race

替换空格

懵懂的女人 提交于 2019-11-28 22:13:52
方法一 :直接用String类的replace方法 方法二思路 :因为String类对象是不可修改的,所以要想对原字符串进行操作就要考虑用Stringbuilder类(Stringbuffer也可以,但一般用Stringbuilder),因为用Stringbuilder创建的对象进行修改删除是不会产生新对象的。既然用了这个类,我们就想一下这个类中有哪些方法跟这道题相关。因为我们是重新创建的Stringbuilder对象,所以append显然有可能用来帮助存储修改后的字符串。(不断的添加到尾部不就形成最终的字符串了吗) 然后就从第一个字符开始判断(用charAt()提取出每个位置的字符是什么),如果跟空字符' '相等就添加%20到队尾,不然就 添加原来的字符到队尾。用循环来操作,最后这个字符串就出来了。 方法三 :第二遍刷剑指offer的时候在来看,现在先快速过一遍。 来源: https://my.oschina.net/u/4120977/blog/3099251

Forcing StreamWriter to change Encoding

你离开我真会死。 提交于 2019-11-28 20:16:34
I am trying to save a file using DialogResult and StringBuilder . After making the text, I am calling the following code to save the file: if (dr == DialogResult.OK) { StreamWriter sw = new StreamWriter(saveFileDialog1.FileName); sw.Write(sb.ToString()); sw.Close(); } I tried to add the second parameter to StreamWriter as Encoding.UTF8 but since the first argument is a string rather than a Stream , it does not compile it. How can I convert that string to a stream to be able to pass the second parameter as Encoding? The reason for this, is that somewhere in my text I have µ but when the file is

httpClinent工具类

心已入冬 提交于 2019-11-28 19:50:00
1 package com.juchn.gateway.common.utils; 2 3 import java.io.BufferedReader; 4 import java.io.IOException; 5 import java.io.InputStream; 6 import java.io.InputStreamReader; 7 import java.security.KeyManagementException; 8 import java.security.KeyStoreException; 9 import java.security.NoSuchAlgorithmException; 10 import java.security.cert.CertificateException; 11 import java.security.cert.X509Certificate; 12 import java.util.ArrayList; 13 import java.util.Iterator; 14 import java.util.List; 15 import java.util.Map; 16 import java.util.Map.Entry; 17 18 import javax.net.ssl.SSLContext; 19 20

Java后端 带File文件及其它参数的Post请求

余生颓废 提交于 2019-11-28 19:29:26
Java 带File文件及其它参数的Post请求 对于文件上传,客户端通常就是页面,在前端web页面里实现上传文件不是什么难事,写个form,加上enctype = “multipart/form-data”,在写个接收的就可以了,没什么难的。 如果要用java.net.HttpURLConnection,java后台来实现文件上传,还真有点搞头,实现思路和具体步骤就是模拟页面的请求,页面发出的格式如下: -----------------------------7da2e536604c8 Content-Disposition: form-data; name=“luid” 123 -----------------------------7da2e536604c8 Content-Disposition: form-data; name=“file1”; filename=“D:\haha.txt” Content-Type: text/plain haha hahaha -----------------------------7da2e536604c8 Content-Disposition: form-data; name=“file”; filename=“D:\huhu.png” Content-Type: application/octet-stream

Why use TagBuilder instead of StringBuilder?

别说谁变了你拦得住时间么 提交于 2019-11-28 18:35:11
what's the difference in using tag builder and string builder to create a table in a htmlhelper class, or using the HtmlTable? aren't they generating the same thing?? Bashir Magomedov TagBuilder is a class that specially designed for creating html tags and their content. You are right saying that result will be anyway a string and of course you still can use StringBuilder and the result will be the same, but you can do things easier with TagBuilder . Lets say you need to generate a tag: <a href='http://www.stackoverflow.com' class='coolLink'/> Using StringBuilder you need to write something

实现发送Outlook appointment/Meeting

本秂侑毒 提交于 2019-11-28 18:03:36
1.直接编码方式 遵循rfc5545x协议标准开发,参考链接 https://tools.ietf.org/html/rfc5545 ,正常遵循此标准开发的Calendar都是兼容的,比如Gmail。 优点:不依赖第三方组件 缺点:实现相对复杂些 2.可以实现功能 发送 修改 取消(取消之后,支持修改,修改之后,状态是未取消状态) 支持添加附件 内容支持html格式 循环功能,支持Daily、Weekly、Monthly、Yearly 3.与Outlook发送的区别: Organizer暂时在Calendar看不到自己的Appointment,所以本文所介绍的方案比较适合作为系统发送的Appointment的场景。 4.实现代码 1 public static void SendMeeting(ref string appointmentID, MailAddress from, MailAddressCollection to, MailAddressCollection cc, MailAddressCollection bcc, string subject, string body, DateTimeOffset dtStart, DateTimeOffset dtEnd, string location, Collection<Attachment>

从源码了解String,StringBuffer和StringBuuilder

不打扰是莪最后的温柔 提交于 2019-11-28 17:50:00
1.String (1)类定义 public final class String implements java.io.Serializable, Comparable<String>, CharSequence String类是个final类,实现了序列化接口,比较大小接口和只读字符序列接口。String和其他八个基本数据类型的包装类共同为不可变类。 (2)主要变量 private final char value[]; String类的底层基本是char类型数组,String的一些基本方法也是调用char数组的基本方法。 (3)主要构造方法 public String() {   this.value = "".value; } String的默认值为""; (4)String常量池 jvm在启动时就会加载的一块空间,符串常量池的特点就是有且只有一份相同的字面量,如果有其它相同的字面量,jvm则返回这个字面量的引用,如果没有相同的字面量,则在字符串常量池创建这个字面量并返回它的引用。通过使用new关键字得对象会放在堆里,而不会加载到字符串常量池,intern()方法能使一个位于堆中的字符串在运行期间动态地加入到字符串常量池中。 (5)字符串拼接 String字符串拼接一般通过用+号实现,正常情况下有两种形式: String a = "ab" + "cd";

1 String、StringBuffer与StringBuilder区别

耗尽温柔 提交于 2019-11-28 17:26:50
区别: String内容不可变,StringBuffer和StringBuilder内容可变; StringBuilder非线程安全(单线程使用),String与StringBuffer线程安全(多线程使用); 如果程序不是多线程的,那么使用StringBuilder效率高于StringBuffer。 (2)String 字符串常量; 这句话总结归纳了String的两个最重要的特点: String是值不可变的常量,是线程安全的(can be shared)。 String类使用了final修饰符,String类是不可继承的。 (3)StringBuffer字符串变量(线程安全)是一个容器,最终会通过toString方法变成字符串; (4)StringBuilder 字符串变量(非线程安全)。 (1) String在修改时不会改变对象自身   在每次对 String 类型进行改变的时候其实都等同于生成了一个新的 String 对象,然后将指针指向新的 String 对象,所以经常改变内容的字符串最好不要用 String 。 (2) StringBuffer在修改时会改变对象自身   每次结果都会对 StringBuffer 对象本身进行操作,而不是生成新的对象,再改变对象引用。所以在一般情况下我们推荐使用 StringBuffer ,特别是字符串对象经常改变的情况下

Java 之 StringBuilder 类

只谈情不闲聊 提交于 2019-11-28 16:28:34
一、字符串拼接问题   由于 String 类的对象内容不可改变,所以每当进行字符串拼接时,总是会在内存中创建一个新的对象。   Demo: 1 public class StringDemo { 2 public static void main(String[] args) { 3 String s = "Hello"; 4 s += "World"; 5 System.out.println(s); 6 } 7 }    上面这段代码,总共产生了三个字符串,即“Hello”,“world” 和 “HelloWorld”。引用变量 s 首先执行 Hello 对象,最终指向拼接出来的新字符串对象,即 HelloWorld。       由此可见,如果对字符串进行拼接操作,每次拼接,都会构建一个新的 String 对象,既耗时,又浪费空间。为了解决这一问题,可以使用 java.lang.StringBuilder 类。 String类有这样的描述:字符串是常量,它们的值在创建后不能被更改。 二、StringBuilder 概述   StringBuilder又称为可变字符序列,它是一个类似于 String 的字符串缓冲区,通过某些方法调用可以改变该序列的长度和内容。   原来StringBuilder是个字符串的缓冲区,即它是一个容器,容器中可以装很多字符串