string-manipulation

Cut out section of string

I wouldn't mind writing my own function to do this but I was wondering if there existed one in the string.h or if there was a standard way to do this. char *string = "This is a string"; strcut(string, 4, 7); printf("%s", string); // 'This a string' Thanks! ...

How does Firefox's 'awesome' bar match strings?

The question is how the string matching is done to find matching entries by the firefox 3 url bar. Substring matching on every entry might be slow. What algorithm can be used to match at any location in a fast way? ...

Removal of ";" from statements ;; in C

I need to remove ";" from statements in C which have ";;". Eg: main() { int i;; int j,k;; int l; for(i=0;i<10;;) {} } should become: main() { int i; int j,k; int l; for(i=0;i<10;;) {} } ...

How would you count occurences of a string within a string (C#)?

I am doing something where I realised I wanted to count how many /s I could find in a string, and then it struck me, that there were about several ways to do it, but couldn't decide on what the best (or easiest) was. At the moment I'm going with something like: string source = "/once/upon/a/time/"; int count = source.Length - source.Re...

Text cleaning and replacement: delete \n from a text in Java

I'm cleaning an incoming text in my Java code. The text includes a lot of "\n", but not as in a new line, but literally "\n". I was using replaceAll() from the String class, but haven't been able to delete the "\n". This doesn't seem to work: String string; string = string.replaceAll("\\n", ""); Neither does this: String string; stri...

C# convert string into its byte[] equivalent

Hello all, At this point most people will be thinking "Ah ill post this..:" byte[] dataB= System.Text.Encoding.ASCII.GetBytes(data); However.. the problem I have is i need the exact value of the bytes with no encoding just the pure value for each byte. For example if the value of the string is (0xFF32) i want it to convert it too {25...

Text replacement efficiency

An extension to my previous question: Text cleaning and replacement: delete \n from a text in Java I am cleaning this incoming text, which comes from a database with irregular text. That means, there' s no standard or rules. Some contain HTML characters like &reg, &trade, &lt, and others come in this form: &#8221, &#8211, etc. Other tim...

Using print instead of sprintf with %s and % and multiple string substitution arguments

In the following ruby code, the output becomes: "x y" x = "x %s" y = "y" z = "z" print x % y %z The %z is ignored. I want the output to be "x y z". To understand the possibilities and limitations of the syntax of Ruby, I want to use only the print command and the %s and % flags. I know how to do this using sprintf but I want to kno...

Concat strings and numbers in C++?

I'm trying to concat "(" + mouseX + ", " + mouseY ")". However, mouseX and mouseY are ints, so I tried using a stringstream as follows: std::stringstream pos; pos << "(" << mouseX << ", " << mouseY << ")"; _glutBitmapString(GLUT_BITMAP_HELVETICA_12, pos.str()); And it doesn't seem to work. I get the following error: mouse.cpp:7...

AS3 string util to convert to x-www-form-urlencoded ?

Is there a library for converting strings in as3 into the application/x-www-form-urlencoded format? Specifically, I am looking for the same functionality as the java URLEncoder http://java.sun.com/javase/6/docs/api/java/net/URLEncoder.html Unfortunately, as3's escape and encodeURIComponent functions don't do it. For example, lots of %...

How can I find a number in a string using Flex?

I want to replace a number with a character at runtime like this: Input: ask 1234 question Result: ask * question What is the best way to accomplish this? ...

Ruby: Merging variables in to a string

Hello, I'm looking for a better way to merge variables in to a string, in Ruby. For example if the string is something like: "The animal action the *second_animal*" And i have variables for Animal, Action and Second Animal, what is the prefered way to put those variables in to the string? Thanks James ...

Trim / remove a tab ( "\t" ) from a string

Can anyone suggest a way of stripping tab characters ( "\t"s ) from a string? CString or std::string. So that "1E10      " for example becomes "1E10". Thanks in anticipation. ...

Bit Operation For Finding String Difference

Dear all, The following string of mine tried to find difference between two strings. But it's horribly slow as it iterate the length of string: #include <string> #include <vector> #include <iostream> using namespace std; int hd(string s1, string s2) { // hd stands for "Hamming Distance" int dif = 0; for (unsigned i = 0;...

How would you implement your string type?

Assume you are designing and implementing a new language from scratch, though you may freely borrow ideas from existing languages/implementations. Question: If a programmer declares a string variable (assume strongly typed), how would you choose to store this variable in memory? There are many use cases, but do you have a particular mo...

Move lines from one .txt file to another

I am trying to move certain lines from one .txt file to another. These lines all follow a certain pattern. I have been looking at using the find command in a batch file, but this does not delete the line from the original file. For example: find \i pattern "d:\example1.txt" >> "d:\example2.txt" Is there any way to achieve this? Th...

Java Regex - reduce spaces in a string

I dont have time to get my head around regex and I need a quick answer. Platform is Java I need the String "Some text   with spaces" to be converted to "Some text with spaces" e.g. 2 spaces to be change to 1 in a String ...

Best way to escape characters like newline and double-quote in NSString

Say I have an NSString (or NSMutableString) containing: I said "Hello, world!". He said "My name's not World." What's the best way to turn that into: I said \"Hello, world!\".\nHe said \"My name\'s not World.\" Do I have to manually use -replaceOccurrencesOfString:withString: over and over to escape characters, or is there an easie...

Join a string using delimiters

What is the best way to join a list of strings into a combined delimited string. I'm mainly concerned about when to stop adding the delimiter. I'll use C# for my examples but I would like this to be language agnostic. EDIT: I have not used StringBuilder to make the code slightly simpler. Use a For Loop for(int i=0; i < list.Length; ...

Separating a string into substrings

I want to separate a string consisting of one or more two-letter codes separated by commas into two-letter substrings and put them in a string array or other suitable data structure. The result is at one point to be databound to a combo box so this needs to be taken into account. The string I want to manipulate can either be empty, cons...