string-manipulation

formatting dates with or without a leading zero in php

How would you convert a datestring that will be formated like... m/d/yyyy H:i:s or mm/dd/yyyy H:i:s... and format it like... yyyy-mm-dd H:i:s I can format either of the two inputs into my desired format, but not both. ...

Parse hour and AM/PM value from a string - C#

What would be the most effective way to parse the hour and AM/PM value from a string format like "9:00 PM" in C#? Pseudocode: string input = "9:00 PM"; //use algorithm //end result int hour = 9; string AMPM = "PM"; ...

C#: Parse substring from a string by detecting whitespace.

If I have various strings that have text followed by whitespace followed by text, how can I parse the substring beginning with the first character in the second block of text? For example: If I have the string: "stringA stringB" How can I extract the substring "stringB" The strings are of various lengths but will all be of...

Replace all text except links

I have many html documents, I need to replace the text "foo" to "bar" in all documents, except in links For example foo<a href="foo.com">foo</a> should be raplaced to bar<a href="foo.com">bar</a> the url in the link (foo.com) should be left untouched. The same case in image links and links to javascripts or stylesheets, only th...

Format string in Objective C

How can i format a string like "Fri Oct 17 00:00:00 +0200 2003" to a simple date string like Fri Oct 17 2003? Is there any easy solution? ...

Separate number from unit in a string in Python

I have strings containing numbers with their units, e.g. 2GB, 17ft, etc. I would like to separate the number from the unit and create 2 different strings. Sometimes, there is a whitespace between them (e.g. 2 GB) and it's easy to do it using split(' '). When they are together (e.g. 2GB), I would test every character until I find a lette...

How-to build tagging system like SO ?

How-to build tagging system like SO ? I'm using a unique textbox on my asp.net mvc website to submit "tags". First of all, i tried to split tags with commas "asp.net, c#, sql server". It works but if user forgot to seperate tags with commas i've a problem to split that string. "asp.net c# sql server" : sql server should be a single ta...

C# - fastest way to compare two strings using wildcards

Is there a fastest way to compare two strings (using the space for a wildcard) than this function? public static bool CustomCompare(this string word, string mask) { for (int index = 0; index < mask.Length; index++) { if (mask[index] != ' ') && (mask[index]!= word[index])) { return false; } ...

iPhone parsing url for GET params

Hello, I have an string which is got from parsing an xml site. http://www.arijasoft.com/givemesomthing.php?a=3434&amp;amp;b=435edsf&amp;amp;c=500 I want to have an NSString function that will be able to parse the value of c. Is there a default function or do i have to write it manually. ...

Nokogiri replace tag values

How to replace "foo" to "bar" ? From <h1>foo1<p>foo2<a href="foo3.com">foo4</a>foo5</p>foo6</h1> to <h1>bar1<p>bar2<a href="foo3.com">bar4</a>bar5</p>bar6</h1> I want only replace tag inner content, without tag attributes. Any ideas ? ...

Can I use strtok() in a Linux Kernel Module?

I need to do a parse on the data written to my module, and the use of the strtok() function of string.h would be useful. However I've tried #include <string.h> and #include <linux/string.h> with no success. Is this possible? Or will I have to write my own strtok function? Thanks ...

Storing and Displaying TextArea user inputs

Hi, How can i handle user inputs with textarea, i need to strip user entered html tags, store text somewhere and display it back in a webpage. I also need to take care about line breaks Any best practices without using <pre> tag ? ...

In python, what is more efficient? Modifying lists or strings?

Regardless of ease of use, which is more computationally efficient? Constantly slicing lists and appending to them? Or taking substrings and doing the same? As an example, let's say I have two binary strings "11011" and "01001". If I represent these as lists, I'll be choosing a random "slice" point. Let's say I get 3. I'll Take the...

C++ std::string InputIterator code to C code

I have some C++ code that I found that does exactly what I need, however I need it in C and I do not know how I could do it in C, so I am hoping someone can help me out. The C++ code is: std::string value( (const char *)valueBegin, (const char *)valueEnd ); This is using the string::string constructor: template<class InputIterator> ...

Can I multiply strings in java to repeat sequences?

I have something like the following: int i = 3; String someNum = "123"; I'd like to append i "0"'s to the "someNum" string. Does it have some way I can multiply a string to repeat it like Python does? So I could just go: someNum = sumNum + ("0" * 3); or something similar? Where, in this case, my final result would be: "123000"....

Removing text inside parens, but not the parens in Perl

OK, I got a weird one that I've been jamming on for awhile (fri afternoon mind does not work I guess). Does anyone know of a away to parse a string and remove all of the text inside parens without removing the parens themselves...but with deleting parens found inside. ie. myString = "this is my string (though (I) need (help) fixing it...

std::string::replace standard implementation?

In every language that I can think of, except C++, the function Replace essentially replaces all pieces of a string, whereas C++'s string class does not support simple operations like the following: string s = "Hello World"; s = s.Replace("Hello", "Goodbye"); echo s; // Prints "Goodbye World" This seems the most common use of any type...

Can I insert PHP variables into a JSON string?

I am using a REST API to POST attributes to a person using json. My request body looks like this: $requestBody = ' { "attribute": { "@id": "", "@uri": "", "person": { "@id": "222", "@uri": "https://api_name_removed.com/v1/People/222" }, "attributeGroup": { ...

how to check "contains" using jquery

Hi, I tried of checking contains option using jquery for the birthday but its getting exception var _dob = "4/10"; // this line doesn't work var _adob = _dob.contains('/') ? _dob.Split('/') : _dob.Split('-'); $('#Month').val(_adob[0]); $('#Day').val(_adob[1]); but i can't able to split.. its resulting in error on getting _adob itsel...

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...