string

c# optimize returning a empty string

Possible Duplicate: In C#, should I use string.Empty or String.Empty or ? Is it better to return string.Empty; instead of return ""; What do you think? ...

C++: Is "my text" a std::string, a *char or a c-string?

I have just done what appears to be a common newbie mistake: First we read one of many tutorials that goes like this: #include <fstream> int main() { using namespace std; ifstream inf("file.txt"); // (...) } Secondly, we try to use something similar in our code, which goes something like this: #include <fstr...

python string format suppress/silent keyerror/indexerror

Hi, Is there a way to use python string.format such that no exception is thrown when an index is missing, instead an empty string is inserted. result = "i am an {error} example string {error2}".format(hello=2,error2="success") here,result should be : "i am an example string success" Right now, python throws a keyerror and stops ...

Failure when retrieving string from the end of a file

I have a simple application which takes a text and password, generates a text writes it in a file then tries to retrieve it and decrypt it. Before the encryption the 'pad' is generated which is a string generated from the password with the length of the text. The problem comes in when I try to retrieve the text, because no matter how I t...

garbage character at end of string?

Hi there I'm reading a string and breaking each word and sorting it into name email and phone number. with the string joe bloggs [email protected] 12345. But once i break everything down, the individual separated variables which hold the name,email and phone number have garbage characters at the end of them. I cant figure out why. test f...

Need a string library for JAVA ME

Hello, Can someone suggest me some JAVA string library for JAVA ME that includes basic string functions like trim,tolower,toupper,replace,substring,etc? Thanks ...

Rails Migration to convert string to integer?

Hi Everyone, Is it possible to change a field that's a string to an integer without clearing the data already entered? The current db structure for the table in question is: create_table :people do |t| t.string :company_id Is this possible using migrations? I'm thinking maybe in the migration drop the old field, create a new one t...

Python Reverse Find in String

ok, I've got a string and an arbitrary index into the string. Now I want find the first occurrence of a substring before the index. A example: I want to find the index of the 2nd I by using the index and str.rfind() s = "Hello, I am 12! I like plankton but I don't like Baseball." index = 34 #points to the 't' in 'but' index_of_2nd_I = ...

CSV row split into string array question

Hi ! How would you split this row to a string array? the problem is Rutois, a.s. , so you cannot directly split with ',' separator.. 543472,"36743721","Rutois, a.s.","151","some name","01341",55,"112",1 thanks ...

Extract action attribute in a Form tag with Regex in C#?

I wanna extract https://www.sth.com/yment/Paymentform.aspx from below string <form id='paymentUTLfrm' action='https://www.sth.com/yment/Paymentform.aspx' method='post'> How can I do it with Regex or somthing ? ...

Heredoc strings in C#

Is there a heredoc notation for strings in C#, preferably one where I don't have to escape anything (including double quotes, which are a quirk in verbatim strings)? ...

How to turn System::String^ into std::string?

So i work in clr, creating .net dll in visual c++. I tru such code: static bool InitFile(System::String^ fileName, System::String^ container) { return enc.InitFile(std::string(fileName), std::string(container)); } having encoder that normaly resives std::string. but here the compiler (visual studio) gives me C2664 error if I str...

Using $x to grab string from rule

I'm trying to do something like this in Bison... loop_for: FOR var_name COLONEQUALS expression TO {printf("%s<=", $2);} expression STEP {printf("%s+=", $2);} expression {printf(")\n");} Code ENDFOR What I'm trying to do is convert a for statement from the fake language's syntax to C's. However, th...

Declaring array using a variable in C++

Hi, I am writing a program that needs to take text input, and modify individual characters. I am doing this by using an array of characters, like so: char s[] = "test"; s[0] = '1'; cout << s; (Returns: "1est") But if I try and use a variable, like so: string msg1 = "test"; char s2[] = msg1; s2[0] = '1'; cout << s1[0] I get an erro...

Should I use string or char[]?

So I want to have a buffer with an array of structs like this: EventItem { tag; // some string or array of characters to describe the value; value; // some integer or something } The value can be anything like int32. What I am concerned about is the tag. If I have an array of these objects, and I make the tag a string, what hap...

how can I read exactly 128 bytes from an fstream into a string object?

How do I read exactly 128 bytes from an fstream into a string object? I wrote some code to read the first 128 bytes of a file and print it and then the last 128 bytes of the file and print that. The last part works, since you can easily iterate to EOF, but how do I get exactly 128 bytes from the front? The code below doesn't work since ...

Problem comparing strings containing numbers

hello i got a problem with comparing two char* variables that contains numbers for example char1 = "999999" and char2="11111111" when i am using the strcmp function it will return that char1 variable is greater than char2 even tho its wrong. (i know that i can compare with using the atoi function till 9 chars inside the string but i need...

Reversible shuffle algorithm using a key

How would I code a reversible shuffle algorithm in C# which uses a key to shuffle and can be reversed to the original state? For instance, I have a string: "Hello world", how can I shuffle it so that later I could be able to reverse the shuffled string back to "Hello world". ...

extending c++ string member functions

I had a need to do a case insensitive find and found the following code which did the trick bool ci_equal(char ch1, char ch2) { return toupper((unsigned char)ch1) == toupper((unsigned char)ch2); } size_t ci_find(const string& str1, const string& str2) { string::const_iterator pos = std::search(str1. begin ( ), str1. end ( ), st...

Quick way to get the contents of a MemoryStream as an ASCII string

I have a JSON string in a MemoryStream. I am using the following code to get it out as an ASCII string: MemoryStream memstream = new MemoryStream(); /* Write a JSON string to memstream here */ byte[] jsonBytes = new byte[memstream.Length]; memstream.Read(jsonBytes, 0, (int)memstream.Length); string jsonString = Encoding.ASCII.GetStri...