string-manipulation

How to check and extract string via RegEx?

I am trying to check if a string ends in "@something" and extract "something" from it if it does. For example, I am trying to do something like this: string temp = "//something//img/@src" if (temp ends with @xxx) { string extracted = (get "src"); ... } else { ... } How can I accomplish this? ...

How to count string occurrence in string?

How can I count the number of times a particular string occurs in another string. For example, this is what I am trying to do in Javascript: var temp = "This is a string."; alert(temp.count("is")); //should output '2' ...

Add character a place in String

Hi I'm trying to make a method that shall help me to spell world right. After addChar have return its work based on the input "famili", I want the result array to contain the word "familiy". Now the method removes a character from the string and replace it with the current char in alpha[], can someone please give me some help to make th...

Is there a java library that converts strings describing measures of time (e.g. "1d 1m 1s") to milliseconds?

When setting issue estimates in JIRA, you can enter a string like "1d 2h 30m" and JIRA will translate this (I'm assuming) into a corresponding number of milliseconds. Is there an available Java library that does this? I'm using a Spring managed bean that takes a property indicating how often a directory ought to be purged, and I'd like...

Strings and character array

what is the difference between the string and character array. how can each element of the string be accessed in C++. ...

Multiple string and condition matching?

I have a program which needs to be able to search through an ArrayList of 'book' objects, and decide which ones meet given criteria. You can search by Name, ID Number, or Year published. Or just by any assortment of the above. Currently i use nested if statements, where a null value means that field wasn't specified and to display all...

single quotation in SQL Server

Possible Duplicate: concatenating string I posted a similar question earlier and asked about using SQL server to output the result with a single quote. Could someone edcuate me please? select ' ' + CustomerID + ',' from dbo.Customers customerid ------------ ALFKI, ANATR, ANTON, AROUT, BERGS, Would like to see the ...

Convert hex representation inside a string to binary equivalent

In a string, replace every occurrence of <0xYZ> with the character of hex value YZ. The < and > characters will be used only for that purpose, the string is guaranteed to be well formatted. Example ('0' = 0x30): A<0x30>B => A0B It's an easy task, but there are many solutions and I was wondering about the best way to do it. ...

how to insert some string in the given string at given index in python

Hi, I am newbie in python and facing some problem , my problem is that how to insert some fields in already existing string for example: suppose i have read one line from any file which contains: line=Name Age Group Class Profession now i have to insert 3rd Field(Group) 3 times more in the same line before Class field...

Getting Spaces to Play Nicely with C++ Input Streams

First consider this sample C++ code: std::string input1, input2, input3; std::cout << "Enter Input 1: "; std::cin >> input1; std::cout << std::endl << "Enter Input 2: "; std::cin >> input2; std::cout << std::endl << "Enter Input 3: "; std::cin >> input3; If for input1 I enter something like "Good day neighbors" then input1 is set to "...

Best way to replace chars in a string from a Hashtable?

Hello, i have a method which gets a string and a Hashtable ... the hash contains the char to be replaced in the key and the value which goes instead as value. Whats the best way to check the hash and replace the chars in the string? Thanks :) ...

Convert string to uppercase in PHP but not html markup

Im a bit stumped on how to make a string uppercase in php while not making the markup uppercase. So for example: <p>Chicken &amp; <a href="/cheese">cheese</a></p> Will become <p>CHICKEN &amp; <a href="/cheese">CHEESE</a></p> Any advice appreciated, thanks! ...

converting string containing keys and values into array

does anyone know an elagant way of turning this string (the list is not definite.. the "keys" and "values" can be added arbitrarily) business_type,cafe|business_type_plural,cafes|sample_tag,couch|business_name,couch cafe into this array? array( [business_type]=>'cafe' [business_type_plural] => 'cafes' [sample_tag]=>'co...

Transforming string data in a SQL Server database

I need to convert some data stored as varchar in a SQL Server database that I want to change from CamelCase to delimiter-separated. I know how to do this trivially in C# but not T-SQL. Any ideas? ...

Is there any way to pass a std::string to a function that accepts a char* and changes its contents?

I'm trying to get back into programming, specifically console games. I'd heard that curses was good for that, so I found a curses tutorial and I'm getting into that. I'm using C++, and naturally I wanted to take advantage of std::string, but functions like getstr() only accept char*. Is there any way to pass a string as a char*, or am I ...

Java replaceAll regex using found instances

I was looking for a way to replace instances of [number][char] or [char][number] like it occurs in mathematical expressions (e.g. 4x + 20y) with [number]*[char] or [char]*[number], I have two problems with that How do i reuse the found number and char => `replaceAll("[0-9999][a-z]", "[1]*[2]")` ? Whats the best way to represent a num...

startsWith() returning unexpected values

The class project has us reading in the title, artist and lyrics of 10,514 songs contained in a single text file. The current section of the project had us write an ordered unrolled linked list and run a search on the title field. The comparator was also written to sort the list by title. We have to keep track of the comparisons requi...

String pattern matching problem

Imagine we have a long string containing the substrings 'cat' and 'dog' as well as other random characters, eg. cat x dog cat x cat x dog x dog x cat x dog x cat Here 'x' represents any random sequence of characters (but not 'cat' or 'dog'). What I want to do is find every 'cat' that is followed by any characters except 'dog' and the...

detect obsolete and incorrect function prototypes with autoconf

I maintain an open source program that builds with autoconf. Right now I'm having a problem with some of my users. They are using a pre-distributed VM from an organization that has an incorrect prototype for strchr in it. Their prototype is: char *strchr(char *,int c); when of course we know it should be: char *strchr(const char *s...

regex help, find first 3 occurrences of a keyword and str_ireplace the content

Given a block of text, I need to parse it for the existing of a keyword. Then on the first appearance of the keyword, I need to wrap bold tags around it (if it doesn't already have them), on the second appearance of the keyword, italics, and on the third, underline. Example using the keyword "help": This is some text with the keyword "...