string

Are helpers really faster than partials? What about string building?

I've got a fancy-schmancy "worksheet" style view in a Rails app that is taking way too long to load. (In dev mode, and yes I know there's no caching there, "Completed in 57893ms (View: 54975, DB: 855)") The worksheet is rendered using helper methods, because I couldn't stand maintaining umpteen teeny little partials for the different sor...

Best way to build a delimited string from a list in java

I have a list of objects, and each object has a string property. For example, I have a List<Person> and each Person has a firstName property. I want to build a comma-delimited, quoted string that looks like this: 'James', 'Lily', 'Michael' Considering that java doesn't seem to have a join method (and besides, this is a bit more compli...

Characters to separate value

Hi, i need to create a string to store couples of key/value data, for example: key1::value1||key2::value2||key3::value3 in deserializing it, i may encounter an error if the key or the value happen to contain || or :: What are common techniques to deal with such situation? thanks ...

[C++] memory leak with std::string when using std::list<std::string>?

I'm working with std::list in my current project. But there is a memory leak somewhere connected with this. So I've tested the problematic code separately: #include <iostream> #include <string> #include <list> class Line { public: Line(); ~Line(); std::string* mString; }; Line::Line() { mString = new std::string("XXXXX...

Simple C string manipulation

Hi all, I trying to do some very basic string processing in C (e.g. given a filename, chop off the file extension, manipulate filename and then add back on the extension)- I'm rather rusty on C and am getting segmentation faults. char* fname; char* fname_base; char* outdir; char* new_fname; ..... fname = argv[1]; outdir = argv[2]; fna...

String Algorithm Question - Word Beginnings

Hi guys. I have a problem, and I'm not too sure how to solve it without going down the route of inefficiency. Say I have a list of words: Apple Ape Arc Abraid Bridge Braide Bray Boolean What I want to do is process this list and get what each word starts with up to a certain depth, e.g. a - Apple, Ape, Arc, Abraid ab - Abraid ar -...

Java library for wiki format strings? [b] to <strong>, [url] to <a href>

Hey. I need a lightweight, easy and customizable (i can control which tags to be enabled/disabled) library to identify and replace "wiki-ish" markup language to HTML in Strings. For example: [b]hello[/b] would be <strong>hello</strong> [url]hello[/url] would be <a href="hello">hello</a> ...

How can I convert a NSString representation of a time value into two NSInteger's containing the hour and minute?

Hello. I'm diving into iOS development and the Objective C language and am building an alarm clock app to become familiar with the SDK and language. I have an NSString object that represents a time, with the range "1:00 am" to "12:59 am". I need to convert this NSString into two NSInteger's that contain the hour value and minute value...

Divide/split a string on quotation marks

I have the following string: I would "surely" like to "go to school". Now, I would like to split this string at the ellipses, that is i would like to get the following output: I would surely like to go to school . ...

Creating a factory method in Java that doesn't rely on if-else

Currently I have a method that acts as a factory based on a given String. For example: public Animal createAnimal(String action) { if (action.equals("Meow")) { return new Cat(); } else if (action.equals("Woof")) { return new Dog(); } ... etc. } What I want to do is avoid the entire if-...

Passing NON null-terminated strings to unmanaged code

Consider the following struct to be sent over TCP to an unmanaged dll [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)] public struct FooMessage { [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 42)] public string foo; //More fields... } Using the following function (credit to Cheeso): public byte[]...

c string compare vs hash compare

I need to compare a string to multiple other constant strings in c. I am curious which is faster, to hash the string I am going to compare and compare it to all the other constant string hashes or just compare the strings as strings. thank you in advance thank you for the answers I am going to be doing many comparisons. can anyone give ...

Multi-split in Python

How would I split a string by two opposing values? For example ( and ) are the "deliminators" and I have the following string: Wouldn't it be (most) beneficial to have (at least) some idea? I need the following output (as an array) ["Wouldn't it be ", "most", " beneficial to have ", "at least", " some idea?"] ...

checking field values for null

I've been working through this for a while and I'm missing the obvious. I'm trying to make sure that if a textbox value is left blank an error isn't thrown and instead a simple message is displayed in the textbox. However, what I've got and several other methods I've tried similar to this haven't worked. I can't figure out why this is...

how to create an utf8 string in Google V8 engine

Hello Im using v8 engine embedded in C++ program and I met a string problem. Well of course v8 engine fully support utf8 string, but i just dont know how. char path[ 1024 ]; GetCurrentDirectory( 1024, (LPWSTR)path ); script->Path = String::New(path); However, the result is the only character "D", for String::New only accepts char*...

Does python have a string contains method?

I'm looking for a string.contains or string.indexof method in Python. I want to do: if not somestring.contains("blah"): continue ...

php script to write files and create zip file

Hi I'm trying to develop an online formbuilder. Each user can build their own forms and I want to be able to provide a button that when clicked will download the users html form page along with its css file as a zip file. I know how to zip the files, but my problem is that the main users html form page doesnt exist as seperate file, it...

PHP - Converting a string into various date formats

Hi I am new to PHP and cannot figure out the best method to convert two strings I have from URL params. I would like to convert: "August 2010" to ---> "2010-08-%" and also: "2010" to ---> "2010-%-%" Thank you in advance! ...

iphone sdk nsstring as object - get text

I'm having an issue with a string which is being returned from a webservice. I am setting the string up in the header file, simple with NSString *serviceUserID; @property (nonatomic, retain) NSString *serviceUserID; then I'm synthesizing it as normal. I can set it using serviceUserID = @"4fffrdscfbg-44-06dfgf-dfgdfg-32eer456134"; b...

passing php variables in query strings

I have a number of url's with different query strings such as view.php?id=5 view.php?id=6 view.php?id=7 on another php page Im using file_get_contents as below: $page = file_get_contents('view.php?id=5'); $file = 'temp/form.html'; file_put_contents($page, $file); This of course only writes the first id '5', so how can i retri...