string

find word before second comma with regex

I want to store the word before the second comma in a string. So if the string looks like this: Hello, my name is David, bla bla. I want to set a variable $test = David ...

How do I know if a regexp has more than one possible match?

I am writing Java code that has to distinguish regular expressions with more than one possible match from regular expressions that have only one possible match. For example: "abc." can have several matches ("abc1", abcf", ...), while "abcd" can only match "abcd". Right now my best idea was to look for all unescaped regexp special cha...

Python string pattern recognition/compression

I can do basic regex alright, but this is slightly different, namely I don't know what the pattern is going to be. For example, I have a list of similar strings: lst = ['asometxt0moretxt', 'bsometxt1moretxt', 'aasometxt10moretxt', 'zzsometxt999moretxt'] In this case the common pattern is two segments of common text: 'sometxt' and 'mo...

Multiline String In Classic Asp

Hi guys, is there any possiblity to get multiline string in classic asp (I think vbscript is the language)? I want a multiline string like in python or groovy: def str = """hello I am a multiline string""" I searched a lot but didn't find a solution. Workarounds are welcome too. BTW: I had in javascript the same problem and solved ...

Map strings to numbers maintaining the lexicographic ordering

I'm looking for an algorithm or function that is able to map a string to a number in such way that the resulting values correspond the lexicographic ordering of strings. Example: "book" -> 50000 "car" -> 60000 "card" -> 65000 "a longer string" -> 15000 "another long string" -> 15500 "awesome" -> 16000 As a function it should be somet...

why would std::string s("??<") output a { instead of ??< as expected???

std::string s("??<"); std::cout << s << std::endl; Why does that output { instead of ??< I'm using Visual Studio 2008. I'm assume it's encoding it but why and what is the encoding called if that is what's happening? This little %#$^*! caused me to look for a bug in my (unit test) code for 30 minutes before I figured out my string wa...

How to replace text in string in C#?

I have this particular piece of code, but its not working. text = text.Replace("\xEF\xBF\xBD", "?"); Does any one knows how to replace the text "\xEF\xBF\xBD" to "?" in C# String. ...

Python joining strings

I have run into a problem joining two strings in Python. I have some code that is like this: for line in sites: site = line for line in files: url = site+line That should be easy I thougth but the strings ends up "looking wierd": http://example.com/ (this is the site) history.txt (Then the line come...

get word before a :- sign in a string with regex

I need to get the amount before a :- sign. So the string would be: bla bla 120:- And then store only 120 in a variable ...

sql server string trim

I need to trim a field in SQL Server table, when i use a select statement. The requirement is that this field populates the dropdownlist in .net page. The maximum length that the data needs to display is 20. If data length is more than that, then it should be cut to 20, if less then the data length should be the length of string. How ...

split a string using find_if

Hi, I found the following code in the book "Accelerated C++" (Chapter 6.1.1), but I can't compile it. The problem is with the find_if lines. I have the necessary includes (vector, string, algorithm, cctype). Any idea? Thanks, Jabba bool space(char c) { return isspace(c); } bool not_space(char c) { return !isspace(c); } vector<s...

Mass string replace in python?

Say I have a string that looks like this: str = "The &yquick &cbrown &bfox &Yjumps over the &ulazy dog" You'll notice a lot of locations in the string where there is an ampersand, followed by a character (such as "&y" and "&c"). I need to replace these characters with an appropriate value that I have in a dictionary, like so: dict =...

how to transform a string to an array with # as a delimiter but only the first one?

(only the first # is a delimiter) 50#some message from me to you #1 or #2 into array ( [amount] => 50 [message] => 'some message from me to you #1 or #2' ) ...

Split a long string into a substring based on a count of chars in C#

I want to split a long string which looks something like this weygjjsgdgkweygwjiewlewegygciefewjknfkeuwyfjkdygwfsn into "weygjjsgdgk" "weygwjiewle" "wegygciefew" "jknfkeuwyfj" "kdygwfsn" in chunks of 10 chars...and format it like "" outside...how can I do this? ...

Creating a stack of strings in C

I want to have a stack that takes strings. I want to be able to push and pop strings off, as well as clear the whole stack. I think C++ has some methods for this. What about C? ...

How to get a variable value if variable name is stores as string?

How can I retrieve the variable value if I have variable name as string? var1="this is the real value" a="var1" Do something to get value of var1 just using variable a. Thanks. So here is the actual problem: I have some AMI's (Amazon Machine Image) and I want to fire few instances of each AMI. As soon as booting is complete, I want to s...

Convert string / character to integer in python

I want to convert a single character of a string into an integer, add 2 to it, and then convert it back to a string. Hence, A becomes C, K becomes M, etc. ...

C# RichTextBox Color parts of a string different colors

I'm trying to color parts of a string to be appended to a RichTextBox. I have a string built from different strings. string temp = "[" + DateTime.Now.ToShortTimeString() + "] " + userid + " " + message + Environment.NewLine; This is what the message would look like once it is constructed. [9:23pm] User: ...

replace multiple values+in SQL query?

I want to do searching for data using users' entry in a field. That is if user enters "D+t+y+g,k,j,h" want to search for values having letters "d and t and y and g or k or j or h". I tried the PHP str_replace function, but didn't like the result. //kw is text field... if($kw != "") { //here we check for some data in field; if yes, c...

VB to Delphi string manipulation code conversion

I have some VB source code and want to convert it to Delphi: Do While Not EOF(textfile) Line Input #textfile, Line Dim retstring() As String retstring = Split(Line, Chr(32)) first = retstring(0) second = retstring(1) I have some text file with lines similar to these: hello all nice to good day I tried some of the sour...