string

How to discard everything after a certain string character in PHP?

Hi, I want to take a string in PHP and discard everything after a certain character. However, it needs to search for not just one character, but an array of them. As soon as it gets to one of the characters in the array, it should return the string before that point. For instance, if I have an array: $chars = array("a", "b", "c"); H...

How to recognize a path inside a string

Just that... I get a string which contains a path to a file plus some arguments. How can I recognize the path? I thought about the index of the '.' in the file... but I don't like it. What about using regular expressions? Can anyone point me in the right direction? Regards Edit: Theses are valid entries... somefile.msi /a C:\MyFolder\S...

Haskell string list through lines

Hey, I'm using the lines functionality to take an input and split up many variables before sending it off to a function. Please look at the run function and tell me why I get the following error. It seems like it should just assign the first string in ln to seq, but I get an error. ERROR:dishonest.hs:33:11: Couldn't match expecte...

Using sprintf without a manually allocated buffer

In the application that I am working on, the logging facility makes use of sprintf to format the text that gets written to file. So, something like: char buffer[512]; sprintf(buffer, ... ); This sometimes causes problems when the message that gets sent in becomes too big for the manually allocated buffer. Is there a way to get sprint...

Format integer to string with 5 digits

I need to have a string, based on an integer, which should always have 5 digits. Example: myInteger = 999 formatedInteger = "00999" What is the best way of doing this in classic ASP? ...

Creating a long string from a result set

I have a result set in MS-SQL within a stored procedure, and lets say it has one VARCHAR column, but many rows. I want to create a comma separated string conataining all these values, Is there an easy way of doing this, or am I going to have to step through each result and build the string up manually? Preferably I'd like to do this in ...

How do you set strings to uppercase / lowercase in Unicode?

This is mostly a theoretical question I'm just very curious about. (I'm not trying to do this by coding it myself or anything, I'm not reinventing wheels.) My question is how the uppercase/lowercase table of equivalence works for Unicode. For example, if I had to do this in ASCII, I'd take a character, and if it falls withing the [a-z]...

Why does Java's hashCode() in String use 31 as a multiplier?

In Java, the hash code for a String object is computed as s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1] using int arithmetic, where s[i] is the ith character of the string, n is the length of the string, and ^ indicates exponentiation. Why is 31 used as a multiplier? I understand that the multiplier should be a relatively large prime ...

Java: convert a char[] to a CharSequence

What is the most direct and/or efficient way to convert a char[] into a CharSequence? ...

How to find the index of the first char in a string that is not in a list.

I know I can loop over the string or build a regex or invert the set (ASCII isn't that big after all) and search for the first instance of that, but Yuck. What I'm looking for is a nice one liner. fewer features is better, LINQ is out (for me, don't ask, it's a long story) The solution I'm going with (unless I see something better) ...

Python - String Literals

I have a string that contains both double-quotes and backslashes that I want to set to a variable in Python. However, whenever I try to set it, the quotes or slashes are either removed or escaped. Here's an example: >>> foo = 'baz "\"' >>> foo 'baz ""' So instead of baz "\" like I want I'm getting baz "". If I then try to escape the b...

How does one escape characters in Delphi string

Delphi strings use single quotes, for example 'a valid string'. How does one specify the ' character within a literal string? How would one refer to the null byte (Unicode code point U+0000)? ...

Display string with whitespace in ASP.NET?

I need to display a string which has a white space on a asp.net page. **Here is what I am doing:** cell = New TableCell cell.Text = value (lets assume value is <" test with whitespace "> row.Cells.Add(cell) and it gets rendered as " test with whitespace " whitespaces within single quotes are not displayed. I want thi...

VBScript: how to set values from recordset to string

This is probably a beginner question, but how do you set a recordset to a string variable? Here is my code: Function getOffice (strname, uname) strEmail = uname WScript.Echo "email: " & strEmail Dim objRoot : Set objRoot = GetObject("LDAP://RootDSE") Dim objDomain : Set objDomain = GetObject("LDAP://" & objRoot.Get("defaultNamingC...

jQuery: Select <a> which href contains some string

Hi, Is it possible using jQuery to select all <a> links which href ends with "ABC" for example, if i want to find this link <a href="http://server/page.aspx?id=ABC"&gt; Thanks in advance ...

Erasing a Char[]

Okay i am working on someone elses code. They do alot of this: char description[256]; description[0]=0; I know this would put a \0 in the first spot of the character array. But is this even a safe way to erase a string? Also visual studio keeps reporting memory leaks, and i've pretty much tied this done to the strings that are used. ...

How to determine if a string is a number in C#

I am working on a tool where I need to convert string values to their proper object types. E.g. convert a string like 2008-11-20T16:33:21Z to a DateTime value. Numeric values like 42 and 42.42 must be converted to an Int32 value and a Double value respectively. What is the best and most efficient approach to detect if a string is an In...

Lightweight regex parser

I'd like to use a Regex parser to aid in some string processing in a C application. I'm ideally looking for something lightweight and open-source. The target platform is an embedded system so we're looking to save as much as possible with memory consumption in particular. I've found a number of options online but was wondering if anyone ...

How do I replace 'php3' with 'php' inside every file in a directory.

Hopefully a nice simple one. I've got a php3 website that I want to run on php 5.2 To start with I'd just like to have every reference to the current "index.php3" _within_each_file_ (recursively) changed to "index.php" and then move on to worrying about globals etc. K. Go! :) Update: Thanks a lot! I realise that my question missed ...

Convert a string to a date in C++

I know this may be simple but being C++ I doubt it will be. How do I convert a string in the form 01/01/2008 to a date so I can manipulate it? I am happy to break the string into the day month year constituents. Also happy if solution is windows only. ...