stringbuilder

Generate a String that matches a RegEx in Python [duplicate]

烈酒焚心 提交于 2019-12-18 02:27:39
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Reversing a regular expression in python I think I ran into a problem that sounds easier than it is... I'm not too sure. I want to define a regular expression, and I want to build a number of strings matching it. Is there any module I can import that has got this functionality? Preferably not a brute-force approach using re.search or re.match . There must be a more elegant way to do that. 回答1: I've been working

Split string after certain character count

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-17 20:26:30
问题 I need some help. I'm writing an error log using text file with exception details. With that I want my stack trace details to be written like the below and not in straight line to avoid the user from scrolling the scroll bar of the note pad or let's say on the 100th character the strings will be written to the next line. I don't know how to achieve that. Thanks in advance. SAMPLE(THIS IS MY CURRENT OUTPUT ALL IN STRAIGHT LINE) STACKTRACE: at

Most efficient initial capacity size for StringBuilder?

落花浮王杯 提交于 2019-12-17 19:47:14
问题 I'm writing lots of stuff to log in bursts, and optimizing the data path. I build the log text with StringBuilder . What would be the most efficient initial capacity, memory management wise, so it would work well regardless of JVM? Goal is to avoid reallocation almost always, which should be covered by initial capacity of around 80-100. But I also want to waste as few bytes as possible, since the StringBuilder instance may hang around in buffer and wasted bytes crop up. I realize this depends

Parsing and modifying xml string with sax parser

假装没事ソ 提交于 2019-12-17 16:52:31
问题 I have an XML file, I need to search for a specific tag in it and update it's value. The problem is that, using Sax parser is "must". I have to find these tags by using Sax Parser "only", dom stax j4dom dom4j parsers are out of consideration. Can I accomplish this task by converting my xml file to a string and parse it by using sax parser and append the new value by StringBuilder object? Would it be okay? Or what would you recommend? 回答1: This is a working code, just add missing imports. It

How does StringBuilder's capacity change?

若如初见. 提交于 2019-12-17 16:41:33
问题 When I have an empty StringBuilder with a capacity of 5 and I write "hello, world!" to it, does the C# standard specify the new capacity of the StringBuilder ? I have a vague memory that it's twice the new string's length (to avoid changing the capacity with every new appended string). 回答1: Depends what version of .NET you're talking about. Prior to .NET 4, StringBuilder used the standard .NET strategy, doubling the capacity of the internal buffer every time it needs to be enlarged.

系统操作日志设计-代码实现

感情迁移 提交于 2019-12-17 10:50:08
上一篇《 系统操作日志设计 》,已基本介绍了为什么要系统操作日志和设计系统操作日志部分内容,如不清楚系统操作日志的 请点这里 。 :) 通了解《 系统操作日志设计 》,已基本明确我们不能通过clone的方式来做日志的设计,因为这样不仅会造成的你数据库表爆炸的情况,还大大的增加了工作量,减少了系统的可维护性。 通过思考大概清楚系统操作日志的设计,以下是其UML图: 通过上图,我们可以了解知道该UML主要由三个表组成,其中一个主表LogSetting和两个从表分别是LogOperation和LogSettingDetail。 那么怎么样才能通过这样的设计来现实我们的日志功能呢? 其实一开始我就觉得通过.net的反射功能可以很简单、很方便的实现这个功能,所以我就顺着一个思路来实现她;通过反射动态的获取Model实体的属性,然后再根据LogSettingDetail配置来匹配所要记录的字段信息。 先来主要的代码吧,发现将思想用文字表达出来还是较困难的,代码比较直接: 代码的实现 using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls

Is .NET's StringBuilder thread-safe

久未见 提交于 2019-12-17 07:51:26
问题 The regular "Thread Safety" section of the MSDN documentation for StringBuilder states that: ...any instance members are not guaranteed to be thread safe... but this statement feels like it has been copied and pasted for almost every class in the Framework: http://msdn.microsoft.com/en-us/library/system.text.stringbuilder.aspx However, these blog posts by Gavin Pugh mention thread-safe behaviours of StringBuilder : http://www.gavpugh.com/2010/03/23/xnac-stringbuilder-to-string-with-no-garbage

interesting OutOfMemoryException with StringBuilder

徘徊边缘 提交于 2019-12-17 07:47:44
问题 I have the need to continuously build large strings in a loop and save them to database wich currently occasioanlly yields an OutOfMemoryException . What is basically going on here is I create a string using XmlWriter with StringBuilder based on some data. Then I call a method from an external library that converts this xml string to some other string. After that the converted string is saved to the database. This whole thing is done repeatedly in a loop about a 100 times for different data.

【leetcode】6.Z字型变换

故事扮演 提交于 2019-12-17 00:45:58
思路: 有几行就有几个StringBuilder,从上往下再从下往上依次向每一行的SB中addchar。 最精彩的地方是flag,用于实现到顶或到底转换方向: 完整code: public String convert ( String s , int numRows ) { if ( numRows == 1 ) return s ; List < StringBuilder > rows = new ArrayList < > ( ) ; for ( int i = 0 ; i < numRows ; i ++ ) rows . add ( new StringBuilder ( ) ) ; //这个flag是精髓 int flag = - 1 ; int row = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { rows . get ( row ) . append ( s . charAt ( i ) ) ; if ( row == 0 || row == numRows - 1 ) flag = - flag ; row += flag ; } StringBuilder res = new StringBuilder ( ) ; for ( StringBuilder singleRow : rows ) res

JAVA开发经验

白昼怎懂夜的黑 提交于 2019-12-15 23:58:55
1.1.直接赋值常量值,禁止声明新对象 直接赋值常量值,只是创建了一个对象引用,而这个对象引用指向常量值。 反例: Long i = new Long ( 1 L ) ; String s = new String ( "abc" ) ; 正例: Long i = 1 L ; String s = "abc" ; 1.2.当成员变量值无需改变时,尽量定义为静态常量 在类的每个对象实例中,每个成员变量都有一份副本,而成员静态常量只有一份实例。 反例: public class HttpConnection { private final long timeout = 5 L ; . . . } 正例: public class HttpConnection { private static final long TIMEOUT = 5 L ; . . . } 1.3.尽量使用基本数据类型,避免自动装箱和拆箱 Java 中的基本数据类型double、float、long、int、short、char、boolean,分别对应包装类Double、Float、Long、Integer、Short、Character、Boolean。JVM支持基本类型与对应包装类的自动转换,被称为自动装箱和拆箱。装箱和拆箱都是需要CPU和内存资源的,所以应尽量避免使用自动装箱和拆箱。 反例: Integer