string-manipulation

Normalizing space characters in Prolog atoms

What is the best way to normalize whitespace characters (space, newline, tab) in a Prolog atom, e.g. in SWI-Prolog. I.e. I would like to have a rule: normalize_space_in_atom(+Atom1, -Atom2) such that Atom2 has any sequence of whitespace characters turned into a single space starts with a non-space ends with a non-space ...

How to print a string without including '\n' in Python

Suppose my string is ' Hai Hello\nGood eve\n' How to eliminate the '\n' in between and make a string print like : Hai Hello Good eve ??? ...

How fast is MySQL compared to a C/C++ program running in the server?

Ok, I have a need to perform some intensive text manipulation operations. Like concatenating huge (say 100 pages of standard text), and searching in them etc. so I am wondering if MySQL would give me a better performance for these specific operations, compared to a C program doing the same thing? Thanks. ...

Should I use Java's String.format() if performance is important?

We have to build Strings all the time for log output and so on. Over the JDK versions we have learned when to use StringBuffer (many appends, thread safe) and StringBuilder (many appends, non-thread-safe). What's the advice on using String.format? Is it efficient, or are we forced to stick with concatenation for one-liners where perform...

How to split a string by using [] in Python

So from this string: "name[id]" I need this: "id" I used str.split ('[]'), but it didn't work. Does it only take a single delimiter? ...

How to use a blank space as padding character to form a string that initializes a control in VB.NET

I want to right pad my string with blank spaces. The following function works for all characters except the blank. myString.PadRight(50,"x") Edit: myString.PadRight(50) does pad a string with blank spaces, but when this string is used in the following statement, the blank padding is gone. myCheckBox.Text = myString.PadRight(50) ...

Truncate String on closest word boundary.

Is it possible to truncate a Java string to the closest word boundary after a number of characters. Similar to the PHP wordwrap() function, shown in this example. ...

New line character in VB.Net?

I am trying to print a message on a web page in vb.net. I am trying to get the messages in new lines. I tried using the "\r\n" and the new line character. But this is getting printed in the page instead of it comming to the next line. Please let me know if there is any alternative. ...

Most optimal way to write a function

SQL code that connects to different databases say dbs= a,b,c Also a big SQL query whose name should be prefixed by database name. So its essentially a string operations on the big query to replace all the above mentioned database names. Whats the most optimal way of writing this in C# ...

C# split string but keep split chars

I'm splitting a string by three different characters but I want the output to include the characters I split by. Is there any easy way to do this? ...

Remove brackets with regular expression in C#

I want to remove square brackets from an SQL string, but only where there is no whitespace inside them. E.g. "SELECT [intId], [The Description]" should return "SELECT intId, [The Description]". I can get the square brackets without spaces inside with the regular expression: \[[^\s]*\] How can the square brackets from these matches b...

VBA String sanitation

I get data imported from an Oracle database and use Excel to create some reports from that. Recently one of our data entry folks has started beginning her entries with "+". Excel than evaluates that and adds = then displays the dreaded ?name# error. The error is error 2029. I tried using If IsError(C.Value) Then C.Value = Repla...

Extra line breaks in this message were removed

I'm creating a big string that ends up getting sent out via email. The string is created as follows: For Each NewClaim As BO.ClaimsByPECLogIDRO In NewClaims strNewClaims &= Environment.NewLine & NewClaim.ClaimPrefix.ToString _ & "-" & NewClaim.ClaimNumber.ToString & " - " & NewClaim.ReportDate.To...

When to use StringBuilder?

I just revisited some of the books that I used to pick up VB.NET. I am not sure I've got this in my head, understand how/what StringBuilder is. What is the guidance for using? Is it best to use it if you are are concatenating 2 strings or 50? Or when the the total string length is greater than 128 characters? Or will you see a perfor...

Is there a good "RichString" class out there?

I'm looking for a class/API that allows you to create and manipulate RichText strings (rtf format) for use with the RichTextbox -like controls. I'm thinking of something like StringBuilder, but that also allows you to specify formatting as you append to it and also go back and edit previously appended segments, as well as doing string...

Can I "multiply" a string (in C#)?

Suppose I have a string, for example, string snip = "</li></ul>"; I want to basically write it multiple times, depending on some integer value. string snip = "</li></ul>"; int multiplier = 2; // TODO: magic code to do this // snip * multiplier = "</li></ul></li></ul>"; EDIT: I know I can easily write my own function to impleme...

Custom manipulator for C++ iostream

Hi, I'd like to implement a custom manipulator for ostream to do some manipulation on the next item being inserted into the stream. For example, let's say I have a custom manipulator quote: std::ostringstream os; std::string name("Joe"); os << "SELECT * FROM customers WHERE name = " << quote << name; The manipulator quote will quote n...

Converting specical characters in XML stream

I have an XML stream which contains special characters such ' stored in a CString object. Is there any method other than replacing individual characters in the stream to convert these special characters ? ...

C# Formatting - How to correctly format a name? I.e. forename or surname

I'm currently being visually assaulted by all of the names that are being displayed and entered on one of my systems. Basically, users have use of an on-screen keyboard and don't tend to write things in neatly! I.e. John Smith ends up getting entered as JOHN SMITH or john smith. I want a way to neatly enter names and display them. I've ...

C++ string parsing (python style)

I love how in python I can do something like: points = [] for line in open("data.txt"): a,b,c = map(float, line.split(',')) points += [(a,b,c)] Basically it's reading a list of lines where each one represents a point in 3D space, the point is represented as three numbers separated by commas How can this be done in C++ without...