string

Building object hierarchy from a 'namespace' string

I'm trying to write a function that takes a string representing a namespace (e.g. "MyCompany.UI.LoginPage") and defines each segment of the namespace as an object if it doesn't already exist. For example, if "MyCompany.UI.LoginPage" wasn't an object, it would evaluate this: MyCompany = {}; MyCompany.UI = {}; MyCompany.UI.LoginPage = {};...

Convert a String Containing an Array to an Array in Ruby

I have a string that contains an array that i would like to convert into an array. How would you do this? I want to convert this: myvar= "[[Date.UTC(2010, 0, 23),0],[Date.UTC(2010, 0, 24),0],[Date.UTC(2010, 0, 25),3],[Date.UTC(2010, 0, 26),0],[Date.UTC(2010, 0, 27),0],[Date.UTC(2010, 0, 28),0],[Date.UTC(2010, 0, 29),0],[Date.UTC(2010,...

Is there an easy way to convert String to Inetaddress in Java?

I am trying to convert strings into Inetaddress. I am not trying to resolve hostnames, the strings are ipv4 addresses, does InetAddress.getByName(String host) work? Or do I have to manually parse it? ...

Returning arrays

main() { .... i = index; while (i < j) { if (ip[i] == "/") { ip[i - 1] = (double.Parse(ip[i - 1]) / double.Parse(ip[i + 1])).ToString(); for (int k = i; k < (ip.Length - 2); k++) { ip[k] = ip[k + 2]; } Array.Resize(ref i...

Why doesn't String's hashCode() cache 0?

I noticed in the Java 6 source code for String that hashCode only caches values other than 0. The difference in performance is exhibited by the following snippet: public class Main{ static void test(String s) { long start = System.currentTimeMillis(); for (int i = 0; i < 10000000; i++) { s.hashCode(); } ...

How do I get the javascript split function to extract null values from a delimited string

I'm trying to parse a delimited string using the javascript split function. I'm using a double character delimiter. So for e.g. if the string contains employee related data with the following fields: Emp Id (mandatory) Name (mandatory) Age (optional) Mobile No (optional) and the delimiter used is |* (i.e. pipe followed by star) I m...

Remove last character from C++ string

Hi! How can I remove last character from a C++ string? I tried st = substr(st.length()-1); But it didn't work. ...

Determine if string in input is a single word in Python

Hello, a brain dead third party program I'm forced to use determines how to treat paths depending if the input supplied is a single word, or a full path: in the former case, the path is interpreted relative to some obscure root directory. So, given that the input can be a full or relative path, or a single word (including underscores ...

How do I store a dict/list in a database?

If I have a dictionary full of nested stuff, how do I store that in a database, as a string? and then, convert it back to a dictionary when I'm ready to parse? Edit: I just want to convert it to a string...and then back to a dictionary. ...

convert string to nsdate

hi, it is possible to convert in iphone sdk (obj-c) a string to nsdate. thank you ...

python string interpolation

What could generate the following behavior ? >>> print str(msg) my message >>> print unicode(msg) my message But: >>> print '%s' % msg another message More info: my msg object is inherited from unicode. the methods __str__/__unicode__/__repr__ methods were overridden to return the string 'my message'. the msg object was initiali...

Rails or Ruby method to auto wrap lines for plain text email

I am building a comment notification system in Rails and I am trying to render user provided comments in a plain text email. When I render the comment, I want to auto wrap the lines when 56 characters are reached. Obviously I don't want to split words. Is there a function in Ruby or RoR for doing this, or do I need to roll my own? Qu...

Why are two identical strings not testing as equal?

Hi, My code: stringFromRecievedData = [[NSString alloc]initWithData:_data1 encoding:NSUTF8StringEncoding]; if (![stringFromRecievedData isEqualToString:lastStringFromRecievedData]) { [lastStringFromRecievedData setString: stringFromRecievedData]; I get the same "not equal" result even in the second round- even when it is the...

correct idiom for std::string constants?

I have a map that represents a DB object. I want to get 'well known' values from it std::map<std::string, std::string> dbo; ... std::string val = map["foo"]; all fine but it strikes me that "foo" is being converted to a temporary string on every call. Surely it would be better to have a constant std::string (of course its probably ...

JQuery: How to get all of a selector's html attributes in one statement, as a string?

Hi all, I've got a div that looks like this: <div id="exampleDiv" class="class1 class2" title="example title"></div> I've selected with JQuery using this statement: var $div = $('#exampleDiv'); What I'd like to get is a string of the tag itself as html, so that I actually get: "<div id='exampleDiv' class='class1'....", etc. Doe...

Java substring check

I have a String2. I want to check whether String2 exists in String1. String1's length can be less or greater or equal than String2. Also String2 can be null or empty sometimes. How can I check this in my Java code? ...

learning string arguments, Flash AS3

I'm bad with strings and probably messed this up. My Flash file receives XML commands and changes the value of the animations (speed, time). Can you improve this string argument or give me an idea what I need to do differently. XML <head> </head> <body> <cnt>1count*count/10</cnt> </body> IS THIS RIGHT? ...

Convert String.Empty to Nothing/Null

Is there a .Net function that does that. I guess if there isn't i have to make my own method. The thing is i have a function. It accepts integers. If you pass a 0 integer or a null value it still works. Problem is that the value of an empty textbox is a String.Empty value. I don't want to use if's. I mean it could but its much nicer i...

C: Trouble with Strings

I am new to C89, and don't really understand how strings work. I am developing on Windows 7. Here is what I am trying to do, in Java: String hostname = url.substring(7, url.indexOf('/')); Here is my clumsy attempt to do this in C89: // well formed url ensured void get(char *url) { int hostnameLength; char *firstSlash; ch...

String equality and SQLite3

I'm experiencing a very strange issue with string equality in SQLite3. I have a table with a text column named type. If I run select distinct type, 2 from mytable order by type (the 2 is there to get the pipe separator), I get: ... Tops|2 ... Tops|2 i.e., the same column appears twice. This is causing me problems because queries wi...