stringbuilder

How can I return a StringBuilder or other string buffer from a PInvoke native callback

耗尽温柔 提交于 2019-12-01 00:31:03
I would like a clean way to increase the size of a StringBuilder() as required for population by native code, the callback method below seems clean, but somehow we get a copy of the buffer instead of the actual buffer - I'm interested in explanations and solutions (preferably sticking to the callback type allocation as it would be nice and clean if only it could be made work). using System; using System.Runtime.InteropServices; using System.Text; namespace csharpapp { internal class Program { private static void Main(string[] args) { var buffer = new StringBuilder(12); // straightforward, we

电商平台适用基础快递查询api接口对接demo解决方案

人走茶凉 提交于 2019-11-30 21:58:03
电商企业从接收订单-配货-打印快递单到后期的快递员收件-快递配送-轨迹查询-签收短信通知等,都需要快递接口的接入。整理目前可以实现如上服务的有 1.各家快递公司:提供快递查询、电子面单打印等 2.快递100:提供在线寄件、快递查询等 3.菜鸟:提供快递查询、电子面单打印等 4.快递鸟:提供预约寄件、快递查询、电子面单打印、代收货款、短信服务等 各家快递公司提供的是一级接口,快递100、菜鸟和快递鸟是集成接口,对于使用快递比较多的企业来说,集成接口相对更好维护一些。所以一般电商都会选择集成的接口。 快递鸟 是专做快递api接口服务的,接口类型也比较全一些,以下以快递鸟接口对接为例(提供的接口demo均为JAVA,如有其它语言demo需要请自行到官网下载) 对接流程:进入 快递鸟官网申请接口 ——对接——联调测试——上线 预约取件-在线预约寄件 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.net

C# StringBuilder类

这一生的挚爱 提交于 2019-11-30 19:27:55
  StringBuilder类位于System.Text命名空间下,使用StringBuilder类每次重新生成新字符串时不是再生成一个新实例,而是直接再原来字符串占用的内存看空间上进行处理,而且它可以动态的分配占用内存空间大小。因此在字符串处理操作比较多的情况下,使用StringBuilder类可以大大提高系统的性能。   默认情况下,编译器会自动为StringBuilder类型的字符串分配一定的内存容量,也可以在程序中直接修改其占用的字节数。   编写测试代码    using System; using System.Text; namespace StringBuilderExample { class Program { static void Main(string[] args) { StringBuilder str = new StringBuilder(); Console.WriteLine("字符串:{0},长度{1}", str, str.Length); Console.WriteLine("内存容量分配:{0}", str.Capacity); str = new StringBuilder("test string."); Console.WriteLine("字符串是:{0},长度:{1}", str, str.Length); Console

Strings are immutable - that means I should never use += and only StringBuffer?

南楼画角 提交于 2019-11-30 18:41:51
Strings are immutable, meaning, once they have been created they cannot be changed. So, does this mean that it would take more memory if you append things with += than if you created a StringBuffer and appended text to that? If you use +=, you would create a new 'object' each time that has to be saved in the memory, wouldn't you? Yes, you will create a new object each time with +=. That doesn't mean it's always the wrong thing to do, however. It depends whether you want that value as a string, or whether you're just going to use it to build the string up further. If you actually want the

String concatenation into StringBuilder java

﹥>﹥吖頭↗ 提交于 2019-11-30 16:21:59
I have a legacy Java file which uses String concatenation to build huge String objects.Its a serious performance issue.Is there a method as such which does the following String test="I am a very bad programmer" +"to use concatenation" +"Instead of StringBuilder" +" or StringBuffer"; to StringBuilder strBuilder= new StringBuilder(); strBuilder.append("I am a bad programmer"); strBuilder.append("to use concatenation"); strBuilder.append("Instead of StringBuilder"); strBuilder.append(" or StringBuffer"); String str= strBuilder.toString(); basically I need a stub in java just to give a the String

String concatenation into StringBuilder java

半城伤御伤魂 提交于 2019-11-30 16:14:32
问题 I have a legacy Java file which uses String concatenation to build huge String objects.Its a serious performance issue.Is there a method as such which does the following String test="I am a very bad programmer" +"to use concatenation" +"Instead of StringBuilder" +" or StringBuffer"; to StringBuilder strBuilder= new StringBuilder(); strBuilder.append("I am a bad programmer"); strBuilder.append("to use concatenation"); strBuilder.append("Instead of StringBuilder"); strBuilder.append(" or

leetcode刷题42

╄→гoц情女王★ 提交于 2019-11-30 16:14:16
今天刷的题是LeetCode43题,这个题是给定两个字符串,求乘积 具体地,我的代码就是根据乘法思路来做的,末位补零来解决高低位的问题 public class Multiply_43_middle { public static void main(String[] args) { System.out.println(solution("9133","0")); } public static String solution(String num1,String num2){ int n=num1.length(); StringBuilder stringBuilder=new StringBuilder();//保存的是结果 for (int i = n-1; i >=0 ; i--) { int multiplier=Integer.parseInt(String.valueOf(num1.charAt(i))); int j=num2.length()-1; int pre=0;//保存需要进位的数 StringBuilder stringBuilder1=new StringBuilder(); for (int k = 0; k <n-1-i ; k++) { stringBuilder1.append(0); } while (j>=0){ int

Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information

给你一囗甜甜゛ 提交于 2019-11-30 12:13:45
通过添加如下的代码catch exception获取具体却是的库的名称: using System.IO; using System.Reflection; using System.Text; try { //The code that causes the error goes here. } catch (ReflectionTypeLoadException ex) { StringBuilder sb = new StringBuilder(); foreach (Exception exSub in ex.LoaderExceptions) { sb.AppendLine(exSub.Message); FileNotFoundException exFileNotFound = exSub as FileNotFoundException; if (exFileNotFound != null) { if(!string.IsNullOrEmpty(exFileNotFound.FusionLog)) { sb.AppendLine("Fusion Log:"); sb.AppendLine(exFileNotFound.FusionLog); } } sb.AppendLine(); } string errorMessage = sb.ToString(); /

String和StringBuffer的常见用法

你说的曾经没有我的故事 提交于 2019-11-30 11:53:43
链接: https://www.nowcoder.com/questionTerminal/fe6b651b66ae47d7acce78ffdd9a96c7?answerType=1&f=discussion 来源:牛客网 /String的用法: //java中String是只读的,没有办法进行变换,因此需要使用StringBuilder。 String.length() //获取字符串的长度 String.charAt(i) //获取第i个字符的内容 String.subString(start) //获取[start,)的字符串 String.subString(start,end) //获取[start,end)中的字符串 char [] c = iniString.toCharArray() //将字符串转为char数组来进行改变字符内容 String.equal() //判断两个字符串是否相等 //StringBuilder的用法: 除了String中支持的方法外,StringBuilder支持字符的增、删、改。 stringBuilder.append( "we" ); //添加we在词尾 stringBuilder.insert( 0 , "we" ); //在0的位置加入后面的内容 stringBuilder.delete( 0 , 1 ); //删除[0,1

Does StringBuilder become immutable after a call to ToString?

这一生的挚爱 提交于 2019-11-30 11:26:37
I distinctly remember from the early days of .NET that calling ToString on a StringBuilder used to provide the new string object (to be returned) with the internal char buffer used by StringBuilder. This way if you constructed a huge string using StringBuilder, calling ToString didn't have to copy it. In doing that, the StringBuilder had to prevent any additional changes to the buffer, because it was now used by an immutable string. As a result the StringBuilder would switch to a "copy-on-change" made where any attempted change would first create a new buffer, copy the content of the old