string

On the longevity of static strings vs seemingly local strings in Java

Given the following snippet A private static final String SQL = "SELECT * FROM TABLE WHERE ID = ?"; and snippet B public List<MyObject> getData(final Long id){ return (List<MyObject>)template.query("SELECT * FROM TABLE WHERE ID = ?",id); } and snippet C public List<MyObject> getData(final Long id){ return (List<MyObject>)t...

Testing a String is null!

OMG. I have a little project to do and the Strings are killing me! Now, I have a String which is null (is taken the value from invoking getParameter() from a servlet). The problem is that, I'm trying to see if it's null, and, even if it's null, in the program is telling me that is not null, but later in program, when I'm using the vari...

Java-Servlets: String null or "null"

http://stackoverflow.com/questions/1533662/testing-a-string-is-null I had this problem(see the link), where I was sure that a String is null, but in fact the String was "null" jcasso told me: Since you get the string from a servlet i can say that this is normal. Java converts a null string to a "null" string on some condit...

Convert Variable Name to String?

I would like to convert a python variable name into the string equivalent as shown. Any ideas how? var = {} print ??? # Would like to see 'var' something_else = 3 print ??? # Would print 'something_else' ...

Can I sort text by its numeric value in Python?

I have dict in Python with keys of the following form: mydict = {'0' : 10, '1' : 23, '2.0' : 321, '2.1' : 3231, '3' : 3, '4.0.0' : 1, '4.0.1' : 10, '5' : 11, # ... etc '10' : 32, '11.0' : 3, '11.1' : 243...

C++, boost asio, receive null terminated string

Hi, How can I retrieve null-terminated string from socket using boost::asio library? Thanks in advance ...

Generate all Permutations of text from a regex pattern in C#

So i have a regex pattern, and I want to generate all the text permutations that would be allowed from that pattern. Example: var pattern = "^My (?:biological|real)? Name is Steve$"; var permutations = getStringPermutations(pattern); This would return the list of strings below: My Name is Steve My real Name is Steve My biological ...

How to rasterize a string (mac)

I'm trying to take an NSString and rasterize it as a bitmap (an array of bytes (RGBA)) The closest I've gotten to any information on how to do something like this was in a forum post that suggested something along the lines of NSString *myString = [[NSString alloc] initWithString:@"This is a test"]; NSSize size = {256, 256}; ...

String concatenation is extremly slow when input is large

Things like the code below is super slow: var str:String = "" for (var i:Number = 0 ; i<1000000000000000000 ; ++i) { str += "someLongLongLongLongLongLongLongLongLongString"; } There is StringBuilder in Java but seems there is no equivalent for AS. So, how do you guys handle large strings concatenation? Update: Thanks for every...

String capitalize - better way

What method of capitalizing is better? mine: char[] charArray = string.toCharArray(); charArray[0] = Character.toUpperCase(charArray[0]); return new String(charArray); or commons lang - StringUtils.capitalize: return new StringBuffer(strLen) .append(Character.toTitleCase(str.charAt(0))) .append(str.substring(...

C# Get control by name

I have a ToolStripMenuItem called "myMenu" How can i access this like so: /* normally i would do: */ this.myMenu... etc /* but how do i access it like this: */ String name = myMenu; this.name... This is because i am dynamically generating ToolStripMenuItems from an xml file and need to reference menuitems by their dynamically genera...

How to match and replace in a mouthful with PHP?

Something like this,but I don't want to do it 2 times: preg_match_all($pattern,$string,$matches); $string = preg_replace($pattern,'',$string); ...

Read bytes from string as floats

I've got a python webserver where small binary files are POST:ed. The posted data is represented as strings. I want to examine the contents of these strings. But to do that, I need to convert each 4 bytes to floats (little endian). How do you do that? ...

newbie question: why are python strings and tuples are made immutable?

a newbie question. i am not sure why strings and tuples were made to be immutable; what are the advantages and disadvantage of making them immutable? please be gentle as it is a newbie question ;-) thanks & wish you a good day!! ...

(Ruby) Is there a function to easily find the first number in a string?

For example, if I typed "ds.35bdg56" the function would return 35. Is there a pre-made function for something like that or do I need to iterate through the string, find the first number and see how long it goes and then return that? ...

Divide a string into smaller parts & organize a structure (C-programming)

Hi again! I am still learning C and I'm having some trouble figuring out how to handle this. Well, I have two structs: struct myStruct { ... struct myString *text[5]; ... } allStructs; struct myString { char part[100]; }; The objective is to have allStruct[n] point to 5 different parts of a text divided into lines of...

C++ stringstream returning extra character?

I've been attempting to use the C++ stringstream class to do some relatively simple string manipulations, but I'm having a problem with the get() method. For some reason whenever I extract the output character by character it appends a second copy of the final letter. #include <iostream> #include <sstream> #include <string> using namesp...

In python, how to check if there are any duplicates in list

example 1: ['one', 'two', 'one'] should return True. example 2: ['one', 'two', 'three'] should return False. ...

String delimiting in Erlang

Is there an equivalent to Perl's """ in Erlang? I'd like to be able to define a pretty long string full of double-quotes without escaping every single one. Is that possible? Feel free to let me know if I'm Doing It Wrong. Thanks! ...

C++ non null terminated char array outputting

Hi I was trying to output a not null terminated char array to a file. Actual thing is, I am receiving packets and then printing their fields. Now as these fields are not null terminated, for example, a data segment which has size of 512 but may or may not be completely occupied. When I write this data to a file I am using simple << ...