I was wondering whether there's a better way of doing this; say we read stdin to a string using fgets() where the string includes a total of n integers (e.g. 5 16 2 34 for n = 4), what would be the best way of extracting them? There has got to be a better way than this hack:
for (i=0, j=0; i<n; ++i, j+=pos)
sscanf(string+j, "%d%n",...
I basically want to check if part of a string begins with a certain sequence - in this case ftp://, or http://. How would I do this?
Thanks
...
I need a short basename function (one-liner ?) for Javascript:
basename("/a/folder/file.a.ext") -> "file.a"
basename("/a/folder/file.ext") -> "file"
basename("/a/folder/file") -> "file"
That should strip the path and any extension.
Update:
For dot at the beginning would be nice to treat as "special" files
basename("/a/folder/.file.a...
I'm looking into overloading the '+' operator for a certain string so I was thinking of subclassing the string class then adding the code in the new class. However I wanted to take a look at the standard string class first but I can't seem to find it... stupid eh?
Can anyone point the way? Even online documentation of the source cod...
For instance, this AudioUnit has to connect to a host through the network, and the hostname has to be configured in a Cocoa View, and has to be saved so that reloading the project restores the hostname.
How would you do that (interface + parameter saving, apart from the network thing of course)?
...
They both mean "new line" but when is one used over the other?
...
I do something like that in the loop :
char* test = "\0";
test = strcat(test, somestr);
...
char* tmp = strstr(test, 0, len);
free(test);
test = tmp;
And get memory leak. What I do wrong?
...
I tried to call foo() inside a string like this:
echo "This is a ${foo()} car";
function foo() {
return "blue";
}
but, it ends up with a syntax error.
I found here something similar, but not exactly what I need:
echo "This is the value of the var named by the return value of getName(): {${getName()}}";
Is that possible to do ...
If I need to get a NUL-terminated char array out of a std::string in a situation where I need to be sure nothing will be allocated, is it safe to use c_str to do so? For example, if I'm inside a destructor and I want to copy some data from a string into a pre-allocated, fixed-size buffer, can I use c_str and be sure it won't throw anythi...
I would like to detect strings that have non-whitespace characters in them. Right now I am trying:
!Pattern.matches("\\*\\S\\*", city)
But it doesn't seem to be working. Does anyone have any suggestions? I know I could trim the string and test to see if it equals the empty string, but I would rather do it this way
...
PHP's wordwrap() function doesn't work correctly for multi-byte strings like UTF-8.
There are a few examples of mb safe functions in the comments, but with some different test data they all seem to have some problems.
The function should take the exact same parameters as wordwrap().
Specifically be sure it works to:
cut mid-word if ...
I have data coming from an nvarchar field of the SQL server database via EF3.5. This string is used to create a Filename and need to remove invalid characters and tried following options but none of them works. Please suggest why this is such an understandable mystery? Am I doing anything wrong?
I went though almost all of the related ...
Hi there. I was just simply wondering how I could limit the length of a string in C#.
string foo = "1234567890";
Say we have that. How can I limit foo to say, 5 characters?
...
This is my string:
msgid """We couldn't set up that account, sorry. Please try again, or contact an ""admin (link is above)."
I want to remove all the double quotes except the first and last one.
How may I do that?
...
hey guys, im just wondering if theres a way to check to see if a string contains any numeric digits in it without using regex. I was thinking of just splitting it into an array and running a search on that, but something tells me theres an easier way
//pseudocode
string aString = "The number 4"
If (aString contains a number) Then ente...
if any user enter long string e.g aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa it destroy the layout of the page. is there any solution which dont destroy our PHP page and str...
Given that we have this kind of string "XXXXXXX XXXXX 756", "XXXXX XXXXXX35665", (X is a character), which is the fasted way to get the number in the end of string?
EDIT: well, this is just-for-fun question. Solve this is quite simple, but I want to know the fastest algorithm to archive this. Rock it on!
...
I was wondering if anyone knows an online service where I could quickly try out .Net's string.Format() various formatting options?
I'm imagining something similar to the multitude of online Regex builders.
I guess Snippet Compiler is the next best thing, but an online version would be easier to use.
...
For some reason, the syntax highlighting below is working how I'd like it to, but this is not how it interprets the code in Visual Studio. When I try to assign multiple lines to a string, it won't let me. Is there a way i can make the following work without combining all of my code into one line or using a += for each new line?
...
Hello. I would like to replace strings that starts with "[id", has a middle part unknown and ends in "]" in a $text. I know how to replace strings that starts with "[id" and ends with "]" but I can't figure out how to include the unknown middle body part as a rule of replace.
Any ideas how to replace like this ?
Thanks.
...