string

Why did Sun specify String.hashCode() implementation?

There seems to be an ongoing debate about whether it is safe to rely on the current implementation of String.hashCode() because, technically speaking, it is guaranteed by the specification (Javadoc). Why did Sun specify String.hashCode()'s implementation in the specification? Why would developers ever need to rely upon a specific imple...

How bad is code using std::basic_string<t> as a contiguous buffer?

I know technically the std::basic_string template is not required to have contiguous memory. However, I'm curious how many implementations exist for modern compilers that actually take advantage of this freedom. For example, if one wants code like the following it seems silly to allocate a vector just to turn around instantly and return ...

Using InvariantCultureIgnoreCase instead of ToUpper for case-insensitive string comparisons

On this page, a commenter writes: Do NOT ever use .ToUpper to insure comparing strings is case-insensitive. Instead of this: type.Name.ToUpper() == (controllerName.ToUpper() + "Controller".ToUpper())) Do this: type.Name.Equals(controllerName + "Controller", StringComparison.InvariantCultureIgnoreCase) Why is this way p...

Delphi strings and reference counting

Delphi uses reference counting with strings. Do this mean that there is only one memory allocation for '1234567890' and all a,b,c,d, e and f.s reference to it? type TFoo = class s: string; end; const a = '1234567890'; b = a; c : string = a; var d: string; e: string; f: TFoo; function GetS...

Is it wrong to terminate a c-string with 0 instead of '\0'?

C-strings are null-terminated which means that in a char-array, the char at index strlen() is a byte with all bits set to 0. I've seen code where, instead of '\0', the integer 0 is used. But since sizeof(int) > sizeof(char), this might actually write beyond the allocated space for the array - am I wrong? Or does the compiler implicitely ...

Assigning memory to double pointer?

I am having trouble understanding how to assign memory to a double pointer. I want to read an array of strings and store it. char **ptr; fp=fopen("file.txt","r"); ptr=(char**)malloc(sizeof(char*)*50); for(int i=0;i<20;i++) { ptr[i]=(char*)malloc(sizeof(char)*50); fgets(ptr[i],50,fp); } instead of thi...

Bug in Mathematica: regular expression applied to very long string

In the following code, if the string s is appended to be something like 10 or 20 thousand characters, the Mathematica kernel seg faults. s = "This is the first line. MAGIC_STRING Everything after this line should get removed. 12345678901234567890123456789012345678901234567890123456789012345678901234567890 1234567890123456789012345678901...

c++ , getting the length of an array using strlen in g++ compiler

could someone explain why i am getting this error when i am compiling the source using following g++ compiler #include <cstdio> #include <string> using namespace std; int main() { char source_language[50]; scanf("%16s\n",source_language); int length = sizeof(source_language); int sizeofchar = strlen(source_language)...

C#: How Should I Handle Arithmetic with Huge Numbers?

I'm writing an app which involves arithmetic with humongous numbers, with very many digits. I've previously written a class that simplifies handling big numbers by defining them as strings and then using slow arithmetic string functions. Is this the best way to do it? If not, how should I approach this problem? Does C# have anything buil...

Playlist for music player in Delphi / List of multiple data items

I would like to have a playlist for my own music player in Delphi / Pascal. I thought that it would be the best solution to have a TStringList with the path of the MP3 file and - additionally - a TListBox with the song names. The matching strings in both lists must be at the same position. So if the user chooses item 5 in TListBox I can...

Switch character case, php

How can i swap around the case of the characters in a string, for example: $str = "Hello, My Name is Tom"; After i run the code i get a result like this: $newstr = "hELLO, mY nAME Is tOM"; Is this even possible? ...

python mapping with strings

I implemented a version of the str_replace function available in php using python. Here is my original code that didn't work def replacer(items,str,repl): return "".join(map(lambda x:repl if x in items else x,str)) test = "hello world" print test test = replacer(test,['e','l','o'],'?') print test but this prints out hello world ...

Strange occurence with string and special character

#include <iostream> #include <string> using namespace std; string mystring1, mystring2, mystring3 = "grové"; int main(){ mystring1 = "grové"; getline( cin, mystring2 ); //Here I type "grové" (without "") cout << "mystring1= " << mystring1 << endl; cout << "mystring2= " << mystring2 << endl; cout << "mystring3= " << mystring3...

Can somebody explain this Javascript method?

Original source: http://twitter.com/tobeytailor/status/8998006366 (x=[].reverse)() === window // true I've noticed that this behavior affects all the native types. What exactly is happening here? ...

string parsing in java

Hello What is the best way to do the following in Java. I have two input strings this is a good example with 234 songs this is %%type%% example with %%number%% songs I need to extract type and number from the string. Answer in this case is type="a good" and number="234" Thanks ...

Checking for end of string in a switch statement, c++

I'm writing a program to basically check if a number is a type float, double, or long double for an assignment using switch statements and a state machine. I am stepping through my program, and it gets all the way to the end except doesn't seem to recognize the string terminator '\0'. So I was wondering if that portion of my code is co...

Is there way was to specify const unichar quoted strings?

Using xcode, I'm trying to get a const c string into a unichar array by doing the following: const unichar *str = "Test String"; but the "Test String" is typed to be (const char *) and produces compiler errors. Is there way to specify a "Test String" that is of type unichar? I was hoping for somethig like: const unichar *str = U"Te...

converting string to lower case in bash shell scripting

Hi, Is there a way in bash shell scripting so that I can convert a string into lower case string. For example, if $a = "Hi all" I want to convert it to $a = "hi all" Thanks a lot for your help ...

create numbered files in C

I need to create files that have the same name, but with a number attached to the end of the filename to indicate that it was the nth file made. So in a for loop, I basically want to do this: char *filename = "file"; strcat(filename, i); // put the number i at the end of the filename Clearly that isn't the way to do it, but any ideas ...

How do I verify that a string is in English?

I read a string from the console. How do I make sure it only contains English characters and digits? ...