2
голосов
8ответов
532 просмотров

Please explain this behavior with character arrays/strings in C

I get this when I was trying something (just for understanding). Please explain this behavior: First attempt: void main() { char src[] = "vinay"; int i; // char name[5] = "test"; char *name= "abcde"; printf("%s \n", name); if (*(name+5) == 'abcde 6th char is n...

14
голосов
5ответов
6258 просмотров

Discard Chars After Space In C# String

I would like to discard the remaining characters (which can be any characters) in my string after I encounter a space. Eg. I would like the string "10 1/2" to become "10"; Currently I'm using Split, but this seems like overkill: string TrimMe = "10 1/2"; string[] cleaned = TrimMe.Split(new cha...

1
голосов
4ответов
2434 просмотров

Putting strings into a 2D chararray in C

How do I put strings into an 2D char array from (for example) a file? char buffert[10][30]; int i = 0; while(!feof(somefile)) { fscanf(somefile, "%s", temp); buffert[i][] = temp; i++; } This will not do it.

2
голосов
3ответов
2668 просмотров

How to return a Ruby array intersection with duplicate elements? (problem with bigrams in Dice Coefficient)

I'm trying to script Dice's Coefficient, but I'm having a bit of a problem with the array intersection. def bigram(string) string.downcase! bgarray=[] bgstring="%"+string+"#" bgslength = bgstring.length 0.upto(bgslength-2) do |i| bgarray << bgstring[i,2] end return bgar...

13
голосов
4ответов
17147 просмотров

Regex match a string with spaces (use quotes?) in an if statement

How would I do a regex match as shown below but with quotes around the ("^This") as in the real world "This" will be a string that can have spaces in it. #!/bin/bash text="This is just a test string" if [[ "$text" =~ ^This ]]; then echo "matched" else echo "not matched" fi I want to do som...

3
голосов
3ответов
31516 просмотров

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?

56
голосов
5ответов
65214 просмотров

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?

0
голосов
1ответов
1988 просмотров

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...

14
голосов
10ответов
7020 просмотров

String object is really by reference?

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 Pro...

9
голосов
8ответов
59002 просмотров

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?

0
голосов
3ответов
144 просмотров

PHP - Split a string

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!

62
голосов
5ответов
44108 просмотров

How to compare 2 strings alphabetically in PHP?

What the title says. Specifically if I have $array1['name'] = 'zoo'; $array2['name'] = 'fox'; How can I determine that alphabetically $array2's name should come above $array1's?

25
голосов
6ответов
10710 просмотров

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 too...

0
голосов
2ответов
382 просмотров

Simplify e-mail body in string?

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. ...

8
голосов
4ответов
23912 просмотров

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#...

2
голосов
2ответов
1455 просмотров

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 fil...

0
голосов
5ответов
1448 просмотров

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 ...

1
голосов
3ответов
1455 просмотров

How to split a string in PHP

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...

23
голосов
3ответов
19170 просмотров

Convert string to DateTime in c#

What is the easiest way to convert the following date created using dateTime.ToString("yyyyMMddHHmmss", CultureInfo.InvariantCulture) into a proper DateTime object? 20090530123001 I have tried Convert.ToDateTime(...) but got a FormatException.

1
голосов
2ответов
8772 просмотров

C++ writing string to file = extra bytes

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. fo...

-1
голосов
1ответов
702 просмотров

VB 2008 - Extracting data from website question

Having more problems coming up with some code for my hwk. All I've been able to do is create the form. We have to get information off of a website and load certain information back into the textboxes on our form. I need a push in the right direction if someone could help. Assignment 6 – Text Pa...

0
голосов
2ответов
933 просмотров

os.popen subprocess conversion

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...

1
голосов
5ответов
2147 просмотров

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 o...

6
голосов
3ответов
2526 просмотров

Can one leverage std::basic_string to implement a string having a length limitation?

I'm working with a low-level API that accepts a char* and numeric value to represent a string and its length, respectively. My code uses std::basic_string and calls into these methods with the appropriate translation. Unfortunately, many of these methods accept string lengths of varying size (i...

1
голосов
5ответов
285 просмотров

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 ...

6
голосов
3ответов
8894 просмотров

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?

0
голосов
3ответов
2086 просмотров

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 clas...

34
голосов
9ответов
15736 просмотров

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";

2
голосов
3ответов
627 просмотров

jruby trim string based on length with ellipses

This is a pretty specific problem, but I'm wondering if anyone would have a brilliant solution. I'm trying to fit a string with a fixed font size in a box of arbitrary size, such that, if the whole string doesn't fit, I want to trim it and ad an ellipses (...). So if my text is "the netherlan...

0
голосов
7ответов
921 просмотров

Need some help with String.format

I'm trying to find a complete tutorial about formatting strings in java. I need to create a receipt, like this: HEADER IN MIDDLE '''''''''''''''''''''''''''''' Item1 Price Item2 x 5 Price Item3 that has a very long name.... Price '''''''''''''''...