string

Invalid Conversion Problem in C++

I have the following snippet: string base= tag1[j]; That gives the invalid conversion error. What's wrong with my code below? How can I overcome it. Full code is here: #include <iostream> #include <vector> #include <fstream> #include <sstream> #include <time.h> using namespace std; int main ( int arg_count, char *arg_vec[] ) { ...

About Comparing String With String

I tried to make character by character comparison under string type, with the following code: vector <int> getQuality(string seedTag, vector <string> &MuTag) { vector <int> Quals; for (unsigned i = 0; i<MuTag.size(); i++) { Quals.push_back(-40); cout << MuTag[i] << " " << seedTag[i] << endl; if...

Assigning C strings

Hello. I’ve got the following code: #include <iostream> using namespace std; int main() { char* a = "foo"; char* b = "bar"; a = b; cout << a << ", " << b << endl; return 0; } This compiles and works, ie. prints bar, bar. Now I would like to demonstrate that what goes on here is not copying a string. I would like to...

Undefined reference to function template when used with string (GCC)

I need to write a templated function replace_all in C++ which will take a string, wstring, glibmm::ustring etc. and replace all occurrences of search in subject with replace. replace_all.cc template < class T > T replace_all( T const &search, T const &replace, T const &subject ) { T result; type...

Using single quote when building a string in Cocoa

I am building a string in Cocoa to be used as a SQL statement which will be passed into the FMDB wrappers for sqlite; however, the database craps out with a BAD_ACCESS failure. I have the following code: prefix = @"SELECT * FROM Table WHERE Field1 LIKE '%"; middle = @"%' OR Field2 LIKE '%"; suffix = @"%' ORDERY BY "; orderby = @"%' ...

Replace content in a string based on Regex.Matches MatchCollection

I've been working on this RegEx for the past day or so and I think I have it worked out so that it returns the data I want. First a little background. I have a content editor that users will be able to edit web pages. They can format text, add links, etc.. standard content editor stuff. When they click save, the editor provides the ab...

Get optarg as a C++ string object

I am using getopt_long to process command line arguments in a C++ application. The examples all show something like printf("Username: %s\n", optarg) in the processing examples. This is great for showing an example, but I want to be able to actually store the values for use later. Much of the rest of the code uses string objects instead o...

What's the most efficient test of whether a PHP string ends with another string?

The standard PHP way to test whether a string $str ends with a substring $test is: $endsWith = substr( $str, -strlen( $test ) ) == $test Is this the fastest way? ...

C# string manipulation - How to remove the first element of each concatenated string in a collection

I am creating concatenated strings based on the data in each row of my ListView control. I need to figure out how to remove the first element in each string which pertains to a single row of the ListView. How might I accomplish this? This is a C# winforms project. Here is my current code: foreach (ListViewItem HazPackE...

C# byte[] to hex string

How do i convert a byte[] to a string, every time i attempt it i get System.Byte[] instead of the value. Also How do i get the value in Hex instead of a decimal? ...

Compact way to extract parts of strings (FASTA header)

Hi, Given the following string: string Header =">day11:1:356617"; How do you extract everything except ">", yielding only: day11:1:356617 I could do standard loop over the string character and keep only other than ">". string nStr =""; for (int i=0; i < Header.size(); i++) { if (Header[i] != ">") { nStr = nStr + He...

Firebird determine if a string is all numbers

I have a VARCHAR field in a Firebird 2.0 table that can contain alphanumeric characters. I need to sort data on this field, sorting all values that contain only numbers as numbers, and sort all other values as 0. For example, if I have four values, "1", "2", "10", "string", I need to sort it as "string", "1", "2", "10". Default sort with...

How can I show a superscript character in .NET GUI labels?

Hello, Is it possible to Build a string or fix the label in the GUI so that I get square meter information to the user. So that the output will look like 21 m2 but the 2 is raised. Regards ...

Using a dictionary when the Key and the Value are the same?

I want to hold about 30 strings in a static "collection". I then need to check the path of an incoming web request against this list. I was thinking of using a StringDictionary with the Key and the Value having the the same values. However it just seems odd when all I really want is a key look up, so I can check for existence rather tha...

How can I detect if a string is empty of characters?

How do I determine if the string has any alpha character or not? In other words, if the string has only spaces in it how do I treat it as an Empty string? ...

Using a sed equivalent in a C program

I have a string input to my program of the form: con*.cc I want this to represent the regular expression, con.*.cc. How can I do this inside a C program? Is there something like sed that I can use? ...

Removing nonnumerical data out of a number + SQL

I'm trying find the best way to remove nonnumerical data from a varchar in SQL e.g. '(082) 000-0000' to '0820000000' or '+2782 000 0000' to '0820000000' The difficulty is i'm not always sure what number formats are coming in, as shown above, so I'd like like everything that is not a number removed essentially. Thanks in advance for a...

Is there a C# case insensitive equals operator?

I know that the following is case sensitive: if (StringA == StringB) { So is there an operator which will compare two strings in an insensitive manner? ...

Algorithm for Counting Sorted Strings (Homebrew "uniq -c")

Hi all, I have the following already sorted data: AAA AAA TCG TTT TTT TTT I want to count the occurrence of each string yielding AAA 2 TCG 1 TTT 3 I know I can do that with "uniq -c", but here I need to do extra processing on the overall C++ code I have. I am stuck with this construct (modified according to 'pgras' suggestion) #...

Which is more efficient, PHP string functions or regex in PHP?

I'm writing PHP code to parse a string. It needs to be as fast as possible, so are regular expressions the way to go? I have a hunch that PHP string functions are more expensive, but it's just a guess. What's the truth? Here's specifically what I need to do with the string: Grab the first half (based on the third location of a substrin...