See also C Tokenizer
Here is a quick substr() for C that I wrote (yes, the variable initializations needs to be moved to start of the function etc, but you get the idea)
I have seen many "smart" implementations of substr() that are simple one liner calls strncpy()!
They are all wrong (strncpy does not guarantee null termination and t...
See also: Is this a good substr() for C?
strtok() and friends skip over empty fields, and I do not know how to tell it not to skip but rather return empty in such cases.
Similar behavior from most tokenizers I could see, and don't even get me started on sscanf() (but then it never said it would work on empty fields to begin with).
I...
Eg if input string is helloworld I want the output to be like:
do
he
we
low
hell
hold
roll
well
word
hello
lower
world
...
all the way up to the longest word that is an anagram of a substring of helloworld. Like in Scrabble for example.
The input string can be any length, but rarely more than 16 chars.
I've done a search and come up ...
I do not understand why Java's String.substring() method is specified the way it is. I can't tell it to start at a numbered-position and return a specified number of characters; I have to compute the end position myself. And if I specify an end position beyond the end of the String, instead of just returning the rest of the String for ...
Edited after getting answers
Some excellent answers here. I like Josh's because it is so clever and uses C++. However I decided to accept Dave's answer because of it's simplicity and recursion. I tested them both and they both produced identical correct results (although in a different order). So thanks again everyone.
Say I have a st...
I"m guessing i'm getting this error because the string is trying to substring a null value. But wouldn't the ".length() > 0" part eliminate that issue?
Here is the Java snippet:
if (itemdescription.length() > 0) {
pstmt2.setString(3, itemdescription.substring(0,38));
} else {
pstmt2.setString(3, "_");
}
I got this error:
...
Hi all i'm trying to migrate to a new mail server so i want to wrote Mysql script to return a table as the following
then export the result as CSV file
sql statement as the following
`select email,clear,email AS domain from postfix_users `
i want to substring any characters preceding the @ and the @ symbol iteself before the domai...
Is this possible? Given that C# uses immutable strings, one could expect that there would be a method along the lines of:
var expensive = ReadHugeStringFromAFile();
var cheap = expensive.SharedSubstring(1);
If there is no such function, why bother with making strings immutable?
Or, alternatively, if strings are already immutable for o...
I am pretty new to C# and I am pretty sure this function can be radically improved:
public static Boolean SuffixExists(String strWhole, String sufx)
{
int iLen = sufx.Length;
if (iLen > 0)
{
String s;
s = strWhole.Substring(strWhole.Length - iLen, iLen);
if (sufx != s) retu...
E.g. to trim the first n characters of the lines, so that
123
1234
becomes
3
34
?
...
I recently discovered that the java.lang.String.substring method does not return a new string, but a view of the original string that was substringed. This can have memory implications. For example, if you're reading an ascii file, and parsing tokens in the file using substring and storing the result of substring in memory somewhere --...
How can i get the string within a parenthesis with a custom function?
e.x. the string "GREECE (+30)" should return "+30" only
...
"abc def"
"abcd efgh"
If I have a large string with a space that separates two substrings of varying length, what's the best way to extract each of the substrings from the larger string?
Because this is a string rather than an array, array syntax s[0] will only retrieve the first letter of the string ('a'), rather than the first subst...
I'd like to create the typical preview paragraph with a [read more] link. Problem is, the content that I'd like to SubString() contains text and html, written by a user with a WYSIWYG editor.
Of course, I check to make sure the string is not null or empty, then SubString() it, problem is that I could end up breaking the html tags, throw...
Hi
I know how to use the substr function but this will happy end a string halfway through a word. I want the string to end at the end of a word how would I go about doing this? Would it involve regular expression? Any help very much appreciated.
This is what I have so far. Just the SubStr...
echo substr("$body",0,260);
Cheers
...
I have a table in a database in SQL server 2005.one of the column is of XML datatype.the content of the columns is like
<info>This is a sample information .Anyone can help </info>
Now i want to query the data in the table with a part of the column value as response.
ie : My desired output is "This is a sample "
What should be the...
I need to substring a variable, and not an object, I know objects such as;
$("div#foo").text().substr(0,1);
But I need to do it on a non-object, for example a variable;
var foo = 'abc';
foo = foo.substr(0,1);
The second example won't work, because it's a non object. The actual problem is that I need to cut the last character off f...
Can anyone point to best algorithm for substring search in another string?
or search for a char array in another char array?
...
The JavaScript String object has two substring functions substring and substr.
substring takes two parameters beginIndex and endIndex.
substr also takes two parameters beginIndex and length.
It's trivial to convert any range between the two variants but I wonder if there's any significance two how the two normally would be used (in d...
I'm trying to find the first and second half of a string of numbers with ruby ignoring the central digit if the length is odd
i.e
input = "102"
first_half = "1"
second_half = "2"
using this code
i = gets
first_half=i[0..(i.length / 2 - 1).floor]
second_half = i[i.length -first_half.length)..i.length - 1]
print "#{first_half}\n#{second...