string-manipulation

SQL string manipulation

I have a table that stores user information. The table has a userid (identity) column in it. The table data is queried by a view which is referenced by a lot of sprocs, but we reference something called auid which is created by the UDF below. The UDF is called in the view and sprocs then join or query from the view based on auid. It ...

Python Case Insensitive Replace

What's the easiest way to do a case-insensitive str.replace in Python? ...

PHP: How to convert single quote to double quote in all HTML tags?

Hi Guys, How can I convert all single quotes to double quotes in all HTML tags only? Is there an easier way to do it? Thanks :) For example: How can I convert this string (actual data from my work): <TEXTFORMAT LEADING='2'><P ALIGN='LEFT'><FONT FACE='Verdana' style="font-size:10' COLOR='#0B333C'>My name's Mark</FONT></P></TEXTFORMAT>...

Ruby experts: can you help/suggest with improving this line of ruby code?

After spliting a tab delimited file I have my required values in a string variable. Unfortunately the source of this file is out of my control. Here are three exact example of what the value might hold: " 5.344" " -2.345" " -.977" Notice the white space, no '0' prefixing the decimal points and the double quotes are in the string. O...

Python String Cleanup + Manipulation (Accented Characters)

I have a database full of names like: John Smith Scott J. Holmes Dr. Kaplan Ray's Dog Levi's Adrian O'Brien Perry Sean Smyre Carie Burchfield-Thompson Björn Árnason There are a few foreign names with accents in them that need to be converted to strings with non-accented characters. I'd like to convert the full names (...

Conversion to a double-escaped string

In C#, I have a filename that needs to converted to be double-escaped (because I feed this string into a regex). In other words, if I have: FileInfo file = new FileInfo(@"c:\windows\foo.txt"); string fileName = file.FullName; fileName is: c:\\\\windows\\\\foo.txt But I need to convert this to have sequences of two literal backslashe...

Python Regex Search And Replace

I'm not new to Python but a complete newbie with regular expressions (on my to do list) I am trying to use python re to convert a string such as [Hollywood Holt](http://www.hollywoodholt.com) to <a href="http://www.hollywoodholt.com"&gt;Hollywood Holt</a> and a string like *Hello world* to <strong>Hello world</strong> ...

String.Replace does not seem to replace brackets with empty string...

Hello, The following bit of C# code does not seem to do anything: String str = "{3}"; str.Replace("{", String.Empty); str.Replace("}", String.Empty); Console.WriteLine(str); This ends up spitting out: {3}. I have no idea why this is. I do this sort of thing in Java all the time. Is there some nuance of .NET string handling that e...

Can you pass a dictionary when replacing strings in Python?

In PHP, you have preg_replace($patterns, $replacements, $string), where you can make all your substitutions at once by passing in an array of patterns and replacements. What is the equivalent in Python? I noticed that the string and re functions replace() and sub() don't take dictionaries... Edited to clarify based on a comment by ric...

Is there a better way to count string format placeholders in a string in C#?

I have a template string and an array of parameters that come from different sources but need to be matched up to create a new "filled-in" string: string templateString = GetTemplate(); // e.g. "Mr {0} has a {1}" string[] dataItems = GetDataItems(); // e.g. ["Jones", "ceiling cat"} string resultingString = String.Format(templateS...

Replace text in WPF Richtextbox.

How to replace a character in WPf richtextbox? ...

C# Best way of assigning values to strings in a loop

Hi, I wonder what is the most efficient way of assigning string variables in a loop. So, for example if I have to browse through a list of nodes and assigning the value of the node to a string, would it be better if I define a variable before the loop starts like string myStringVariable = string.Empty foreach(XmlNode node in givenNodes)...

Help on a better way to parses digits from a String in Java

I have a string which contains digits and letters. I wish to split the string into contiguous chunks of digits and contiguous chunks of letters. Consider the String "34A312O5M444123A". I would like to output: ["34", "A", "312", "O", "5", "M", "444123", "A"] I have code which works and looks like: List<String> digitsAsElements(String...

Problems launching a process with Process.Start() - how do I construct the argument list?

I've got this: string cmd = " -i """ + finPath + """ -ar 44100 -ab 160k """ + foutPath + """"; and I need to pass it to command prompt from C# using Systems.Diagnostics.Process. No combination seems to work. Program works just fine if I run it in command prompt. Also runs just fine if I use the same string in VB.Net finPath has spac...

How can I word wrap a string in Perl?

I'm trying to create a loose word wrapping system via a regex in Perl. What I would like is about every 70 characters or so to check for the next whitespace occurrence and replace that space with a newline, and then do this for the whole string. The string I'm operating on may already have newlines in it already, but the amount of text b...

Need Help Optimizing php string difference function

I created this function and it works on small strings, but for longer strings it times-out. I'm looking for a way to make the function work faster and not timeout, or a better way to accomplish what I want. function find_diffs($string1, $string2) { $array1 = preg_split("/\b/", $string1); $array2 = preg_split("/\b/", $string2); ...

How do you reverse a string in place in JavaScript?

How do you reverse a string in place (or in-place) in JavaScript when passed to a function with a return statement? All without using the built-in functions? .reverse(), .charAt(), etc. Thanks! ...

Removing starting spaces in Python?

I have a text string that starts with a number of spaces, varying between 2 & 4. What's the easiest & simplest way to remove them ie. remove everything before a certain character? Cheers! ...

fastest way to replace string in a template

I have some template string this is my {0} template {1} string which I plan to put user values in using String.Format(). The string actually is longer so for readability I use: this is my {goodName1} template {goodName2} string And then String.Replace each parameter with its value. How can I get the highest performance and ...

Unusual String Error

I am working with some sample code generously given to me by this answer, and when i enter a long string to match it crashes at some point with an IndexOutOfRangeException. What's strange is that when i inspect the string, it appears to be set to the words "System.Char[]". Why does this happen, and how can i fix it? ...