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!
...
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?
...
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;;)
{}
}
...
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...
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...
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...
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 ®, &trade, <, and others come in this form: ”, –, etc. Other tim...
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...
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...
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 %...
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?
...
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
...
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.
...
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;...
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...
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...
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
...
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...
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; ...
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...