string-manipulation

How to process this string via regular expression

my string style like this expression1/field1+expression2*expression3+expression4/field2*expression5*expression6/field3 a real style mybe like this: computer/(100)+web*mail+explorer/(200)*bbs*solution/(300) "+" and "*" represent operator "computer","web"...represent expression (100),(200) represent field num . field num may not exi...

How to Reassign value of StringBuffer?

How can we re assign the value of a StringBuffer or StringBuilder Variable? StringBuffer sb=new StringBuffer("teststr"); Now i have to change the value of sb to "testString" without emptying the contents. I am looking at a method which can do this assignment directly without using separate memory allocation.I think we can do it only a...

Extracting URLs (to array) in Ruby

Good afternoon, I'm learning about using RegEx's in Ruby, and have hit a point where I need some assistance. I am trying to extract 0 to many URLs from a string. This is the code I'm using: sStrings = ["hello world: http://www.google.com", "There is only one url in this string http://yahoo.com . Did you get that?", "The first URL in t...

C: evaluate part of the string

I cant find an expression to evaluate a part of a string. I want to get something like that: if (string[4:8]=='abc') {...} I started writing like this: if (string[4]=='a' && string[5]=='b' && string[6]=='c') {...} but if i need to evaluate a big part of string like if (string[10:40] == another_string) {...} then it gets to wri...

jQuery: strip domain name from url (string)

hi all, i'm accessing the stylesheet collection like this: var css = document.styleSheets[0]; it returns eg. http://www.mydomain.com/css/main.css question: how can i strip the domain name to just get /css/main.css ? thx ...

iPhone dev: Replace uppercase characters in NSString with space and downcase

I have: NSString *promise = @"thereAreOtherWorldsThanThese"; which I'm trying to transform into the string: @"There are other worlds than these" I'm guessing this is a regex job, but I'm very new to Objective C, and have so far had no luck. I would greatly appreciate any help! ...

function to remove duplicate characters in a string

The following code is trying to remove any duplicate characters in a string.Iam not sure if the code is right??Can anybody help me with the working of the code i.e whats actually happening when there is a match in characters? public static void removeDuplicates(char[] str) { if (str == null) return; int len = str.length; if (len <...

Best way to manipulate and compare strings

I'm developing a REST service, so a request could be something like this: /Data/Main/Table=Customers/ I need to get the segments one by one, and for each segment I will decide wich object I'm going to use, after I'll pass to that object the rest of the query so it can decide what to do next. Basically, the REST query is a path on a tre...

How to convert hexadecimal representation of data to binary data in PHP?

I'm familiar with php's function bin2hex() for converting binary data to its hexadecimal representation. However, what is the complement function to convert the hexadecimal representation of the data back to binary data? For example: $foo = "hello"; $foo = bin2hex($foo); echo $foo; // Displays 68656c6c6f How do I turn it back to hel...

A regular expression that will allow a string with only one Capital Letter

The string should be 6 - 20 characters in length. And it should contain 1 Capital letter. I can do this in code using C# string st = "SomeString" Regex rg = new Regex("[A-Z]"); MatchCollection mc = rg.Matches(st); Console.WriteLine("Total Capital Letters: " + mc.Count); if (mc.Count > 1) { ...

How to read values from file. tokenizer

I have a file in which each line contains two numbers. The problem is that the two number are separated by a space, but the space can be any number of blank spaces. either one, two, or more. I want to read the line and store each of the numbers in a variable, but I'm not sure how to tokenize it. i.e 1 5 3 2 5 6 3 4 83 54 23 ...

How to get specific line from a string in C#?

I have a string in C# and would like to get text from specific line, say 65. And if file does not have so many lines I would like to get "". How to do this? ...

how to retrieve substring from string having variable length of character in php?

Hello I have some data in the format of C222 = 50 C1234P687 = 'some text' C123YYY = 'text' C444 = 89 C345 = 3 C122P687 = 'some text' C122YYY = 'text' .... .... so basically 3 different forms "C" number = value, example - C444 = 89 "C" number "P" number = value, example - C123P687 = 'some text' "C" number "YYY" = value Only number...

How to replace empty string with zero in comma-separated string?

"8,5,,1,4,7,,,,7,,1,9,3,6,,,8,6,3,9,,2,5,4,,,,,3,2,,,7,4,1,1,,4,,6,9,,5,,,,5,,,1,,6,3,,,6,5,,,,7,4,,1,7,6,,,,8,,5,,,7,1,,3,9," I'm doing a programming challenge where i need to parse this sequence into my sudoku script. Need to get the above sequence into 8,5,0,1,4,7,0,0,0,7,0,1,9,3,6,0,0,8......... I tried re but without success, help ...

java: how can i trim beginning and ending double quote in a string ?

Hi All. I would like to trim a beginning and ending double quote (") from a string. how can I achieve that in java? thanks! ...

Problems removing a " from a string

Hi, I have a string that ends with a " (quotation mark) that I want to get rid of. However, because XCode usually requires you to enter the text you wish to remove using stringByReplacingOccurrencesOfString in @"texttoremove" format, you can't use the quotation marks in the space as it thinks you are closing the text. Update: Now I can...

Best way to split a string by word (SQL Batch separator)

I have a class I use to "split" a string of SQL commands by a batch separator - e.g. "GO" - into a list of SQL commands that are run in turn etc. ... private static IEnumerable<string> SplitByBatchIndecator(string script, string batchIndicator) { string pattern = string.Concat("^\\s*", batchIndicator, "\\s*$"); RegexOptions opti...

How to get first and last occurence of an array of words in text using PHP?

$arr = array('superman','gossipgirl',...); $text = 'arbitary stuff here...'; What I want to do is find the first/last occurencing index of each word in $arr within $text,how to do it efficiently in PHP? ...

Python: how to enclose strings in a list with < and >

Hello, i would like to enclose strings inside of list into <> (formatted like <%s>). The current code does the following: def create_worker (general_logger, general_config): arguments = ["worker_name", "worker_module", "worker_class"] __check_arguments(arguments) def __check_arguments(arguments): if len(sys.argv) < 2 + len...

Efficient splitting of elements in a field

I have a field in a text file exported from a database. The field contains addresses but sometimes they are quite long and the database allows them to contain multiple lines. When exported, the newline character gets replaced with a dollar sign like this: first part of very long address$second part of very long address$third part of v...