string

How to filter out a set of strings A from a set of strings B using Bash

Hi, I have a list of strings which I want to remove from a super set of another strings, not in a any specific order and thus constructing a new set. Is that doable in Bash? ...

[PHP] Only allowing certain characters in string

Hi, I have been looking for a way to create a function to check if a string contains anything other than lower case letters and numbers in it, and if it does return false. I have searched on the internet but all I can find is old methods that require you to use functions that are now deprecated in PHP5. So how do we do it in PHP5? ...

How to replace string only once without regex in Java?

I need to replace a dynamic substring withing a larger string, but only once (i.e. first match). The String class provides only replace(), which replaces ALL instances of the substring; there is a replaceFirst() method but it only takes regexp instead of a regular string. I have two concerns with using regex: 1) my substring is dynamic...

Efficient way to compare two strings (ordering of characters irrelevant)

I am trying to come up with an algorithm to compare two strings. It would register a match any words that contain the same letters. For example rent and tern would be equivalent because they both contain the letters r,e,n,t. EDIT I apologize for being so vague. The comparison is going to be made on two sets of a few thousands of words h...

C# - Count string length and replace each character with another

How can I count the number of characters within a string and create another string with the same number of characters but replace all of them with a single character such as "*"? Thank you. ...

Why am I receiving an unexpected T_CONSTANT_ENCAPSED_STRING error?

I am getting this error: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in C:\wamp\www\vacation_showcase\admin\participants_edit_list.php on line 17 This is my sql statement: $sql = 'SELECT substring_index(description,' ',100) as preview, name, extra_line, link FROM participants ORDER BY name ASC'; I dont know why...

Casting string type with GetDlgItemText() for use as string buffer in C++

I am stumped by the behaviour of the following in my Win32 (ANSI) function: (Multi-Byte Character Set NOT UNICODE) void sOut( HWND hwnd, string sText ) // Add new text to EDIT Control { int len; string sBuf, sDisplay; len = GetWindowTextLength( GetDlgItem(hwnd, IDC_EDIT_RESULTS) ); if(len > 0) { // HERE: sBuf.resize(le...

How do I interpolate a Perl hash element in a string?

How do I print a hash from within a string, as in print "\n[*] Query : $select { query }"; versus print "\n[*] Query : " . $select { query }; ...

Push Call to STL Queue<std::string> causes Segfault when String is read off socket

I'm using an STL Queue as an input queue, it's containing std::strings, which I have aliased as String using a typedef. I'm reading the input string off a socket - using Berkeley sockets. It is read into a char buffer array and then used to set a string which is passed to the queue. It only happens for the input queue - the output que...

Why is there a different string class in every C++ platform out there?

While I like programming in C++, I hate the idea of: std::basic_string vs QString vs wxString vs ............. Doesn't the standard string class satisfy the needs for these frameworks? I mean what is wrong with the standard string class?! Just to emphasize, that below is the important question: Do you learn "the" string class of the fra...

Fastest way to convert '(-1,0)' into tuple(-1, 0)?

I've got a huge tuple of strings, which are being returned from a program. An example tuple being returned might look like this: ('(-1,0)', '(1,0)', '(2,0)', '(3,0)', '(4,0)', '(5,0)', '(6,0)') I can convert these strings to real tuples (with integers inside), but i am hoping someone knows a nice trick to speed this up. Anything i've ...

Specify glob size range in Regex

How do I define a minimum and maximum (possibly unbounded) number of times a certain pattern should repeat itself? I know there's ? and *, with which I could build the pattern by repeating it a certain amount of times, but I know there's a special notation for it using {}, I just can't remember how it is. ...

str.format(list) with negative index doesn't work in Python

I use a negative index in replacement fields to output a formatted list,but it raises a TypeError.The codes are as follows: >>> a=[1,2,3] >>> a[2] 3 >>> a[-1] 3 >>> 'The last:{0[2]}'.format(a) 'The last:3' >>> 'The last:{0[-1]}'.format(a) Traceback (most recent call last): File "", line 1, in TypeError: list indices must be integers...

Regex.Replace, String.Replace or StringBuilder.Replace which is the fastest?

Hi all, I need to replace all system. environment.newline (s) in the string returned by my function with "System.Environment.Newline + \t" (i'm trying to apply indenting) and I need to do this several times . now my question is which one is the fastest way to do this ? I know that stringbuilder is faster than string.replace but I dont k...

What is the proper way to compare an element of an std::string with a character?

Hello, I am not a very experienced C++ programmer, i get a warning when i do the following: if (myString[i] != 'x') { } what is the appropriate way to compare these? thanks for your help! ...

Is there a way to split a string by every nth seperator in Python?

For example, if I had the following string: "this-is-a-string" Could I split it by every 2nd "-" rather than every "-" so that it returns two values ("this-is" and "a-string") rather than returning four? ...

What is the error in this string loop?

for (int i = len-2; index>= 0; index --) ...

Problem with EOF in C

I'm writing a program which is supposed to read two strings that can contain line breaks and various other characters. Therefore, I'm using EOF (Ctrl-Z or Ctrl-D) to end the string. This works fine with the first variable, but with the second variable, however, this seems to be problematic as apparently something is stuck in the input b...

How to allow spaces in string when searching for position of substring in C?

I'm stuck on part of my homework, I had to find the rightmost occurrence of a substring inside of a string. I have the first part done (can find substring in single word strings), but now I am having trouble with the second part. I have to use a modified version of getline in order to allow multi-word strings (aka with spaces). Here's...

Matching regular expressions against non-Strings in Ruby without conversion

If a Ruby regular expression is matching against something that isn't a String, the to_str method is called on that object to get an actual String to match against. I want to avoid this behavior; I'd like to match regular expressions against objects that aren't Strings, but can be logically thought of as randomly accessible sequences of ...