string

What's the cleanest way to write a multiline string in JavaScript?

It doesn't really have to add newlines, just something readable. Anything better than this? str = "line 1" + "line 2" + "line 3"; ...

CComBSTR memory allocation

I have a "const char* str" with a very long string. I need to pass it from a cpp client to a .Net COM method which expects BSTR type. Currently I use: CComBSTR bstr = str; This has the following issues: Sometimes this line fails with out of memory message When I pass the bstr to the COM class it takes a lot of memory (much more than...

How can I add an underscore before each capital letter inside a Java String?

I have a string like this "HelloWorldMyNameIsCarl" and I want it to become something like "Hello_World_My_Name_Is_Carl". How can I do this? ...

sstream not working...(STILL)

I am trying to get a double to be a string through stringstream, but it is not working. std::string MatlabPlotter::getTimeVector( unsigned int xvector_size, double ts ){ std::string tv; ostringstream ss; ss << "0:" << ts << ":" << xvector_size; std::cout << ss.str() << std::endl; return ss.str(); } It outputs only...

Find the rightmost occurence of a character in C?

Hey all, I'm trying to find the numeric position of a character or number of characters in a string. I'm able to figure out how to see where character "a" is in the string "abcd" but if I put "abcda" it only prints out 0, meaning that it counts only the first instance. I want to find the last or rightmost occurence of this string. Her...

os.popen subprocess conversion

Hi Pythoners. This snippet gets me the dotted quad of my BSD network interface. I would like to figure out how to use the subprocess module instead. ifcfg_lines = os.popen("/sbin/ifconfig fxp0").readlines() x = string.split(ifcfg_lines[3])[1] Seems as if I can't use subprocess in exactly the same way. I don't think I want shell=True ...

C++ writing string to file = extra bytes

Hello, I am using c++ to look through 256 counts and write the ASCII representative to a file. If i use the method of generating a 256 character string then write that string to the file, the file weighs 258bytes. string fileString = ""; //using the counter to attach the ASCII count to the string. for(int i = 0; i <= 256; i++) { file...

Convert string to DateTime in c#

Hi, can someone please tell me the easiest way to convert the following date created using.. dateTime.ToString("yyyyMMddHHmmss", CultureInfo.InvariantCulture) into a proper DateTime object? 20090530123001 thanks. NB: I have tried Convert.ToDateTime(...) but got a FormatException. ...

How to split a string in PHP [solved]

Hello, I have a long string resulted from encoding a binary file -an image file- (in base 64). Is there a particulary method (or rule) I should follow when spliting it? Edit: I want to write the string to a xml file, but in order to do this I must split it in smaller chunks. Edit2: I would like to split it by length (I think that is more...

string.replace function bug ?

string s1 = "[quote=useruk1]<p>im useruk1</p>[/quote]<p>hi  im mod1-probe</p>"; string s2 = "hi im mod1-probe"; string s3 = "blah blah"; string s4 = s1.Replace(s2, s3); Console.Write(s4); seems to be not working. Any ideas? How to solve this problem? UPDATE: problem was with the space, normal space ASCII value is 32 and above strin...

String replacing in a file by given position

I have a file opened in 'ab+' mode. What I need to do is replacing some bytes in the file with another string's bytes such that: FILE: thisissomethingasperfectlygood. string: 01234 So, for example, I seek for the position (4, 0) and I want to write 01234 in the place of "issom" in the file. Last appearance would be: this01234eth...

How to easily display double quotes in strings in C#?

If you have a string with a numerous double quotes, in PHP you can do this: file.WriteLine('<controls:FormField Name="Strasse" LabelText="Strasse">'); in C# you have to do this: file.WriteLine("<controls:FormField Name=\"Strasse\" LabelText=\"Strasse\">"); Is there a way in C# to do what you can do above in PHP, something like th...

Simplify e-mail body in string?

Hi, I'm just wondering about this one. I'm creating an ASP.NET webform containing lots of textboxes etc. And I want to send an e-mail based on this stuff. And the e-mails body needs to go into a string. And the string is supposed to contain HTML code, but the syntax changes because of the string. So how can I simplify this? Is there a...

Is std::string thead-safe with gcc 4.3?

I'm developing a multithreaded program running on Linux (compiled with G++ 4.3) and if you search around for a bit you find a lot of scary stories about std::string not being thread-safe with GCC. This is supposedly due to the fact that internally it uses copy-on-write which wreaks havoc with tools like Helgrind. I've made a small progr...

PHP - Split a string

Hi all, Another n00b question. $ab = "A00000001" echo $a; // gives result "A" echo $b; // gives result "1" $ab = "B01250" echo $a; // gives result "B" echo $b; // gives result "1250" What's the easiet single way to convert "ab" to "a" and "b" in both examples above? Thanks! ...

How to remove first two and last two chars in a string?

Is there an easy way to remove the first 2 and last 2 chars in a string? I have this string: \nTESTSTRING\n How could I easily delete them? ...

C# .NET String object is really by reference?

Hi, I have being studying (newbie) .NET and I got some doubts. Reading from a book examples I learnt that String are object then Reference Type. So, I did this test and the result was different what I expected: I'm really curious, is this an exception because "string" are special types? class Program { static void Main(string[]...

How do I go about Flushing STDIN here?

I have a function (in C) that gets input from the user, (using scanf) stores it in an unsigned int, and returns the input to other functions that handle it: unsigned int input(void) { unsigned int uin; scanf("%u", &uin); return val; } I was wondering, being as I ought to flush stdin, I'd want to use a while loop using get...

Rounding Decimals with New Python Format Function

How do I round a decimal to a particular number of decimal places using the Python 3.0 format function? ...

C# - Pass string to textbox in web page using the webbrowser control

Is there a way to take the value of a string and pass that to a textbox within a web page while using the webbrowser control? ...