string

How to use a blank space as padding character to form a string that initializes a control in VB.NET

I want to right pad my string with blank spaces. The following function works for all characters except the blank. myString.PadRight(50,"x") Edit: myString.PadRight(50) does pad a string with blank spaces, but when this string is used in the following statement, the blank padding is gone. myCheckBox.Text = myString.PadRight(50) ...

Is there any way to determine how many characters will be written by sprintf?

I'm working in C++. I want to write a potentially very long formatted string using sprintf (specifically a secure counted version like _snprintf_s, but the idea is the same). The approximate length is unknown at compile time so I'll have to use some dynamically allocated memory rather than relying on a big static buffer. Is there any ...

New line character in VB.Net?

I am trying to print a message on a web page in vb.net. I am trying to get the messages in new lines. I tried using the "\r\n" and the new line character. But this is getting printed in the page instead of it comming to the next line. Please let me know if there is any alternative. ...

To determine if one of the Strings from a list contains the intial part of a specified string using LINQ

I want to achieve the following functionality using LINQ. Case 1: listOfStrings = {"C:","D:","E:"} myString = "C:\Files" Output: True Case 2: listOfStrings = {"C:","D:","E:"} myString = "F:\Files" Output: False ...

Why can't I put an iterator in map?

I have a map defined like this std::map<some_key_type, std::string::iterator> mIteratorMap; And a huge string named "mHugeString". Then I walk trough the string collecting iterators like this: std::string::iterator It=mHugeString.begin(); std::string::iterator EndIt=mHugeString.end(); for(;It!=EndIt;++It){ ...defining a key element...

String formatting in Python

I want to do something like String.Format ("[{0}, {1}, {2}]", 1, 2, 3) which returns: [1, 2, 3] How do I do this in Python? ...

How do you call an ASHX from JavaScript?

I want to call an ASHX file and pass some query string variables from JavaScript and get the return string into a string in the JavaScript. How would I do this? The ASHX file is already coded to response.write a string based on whatever the query strings are. ...

Strings as Primary Keys in SQL Database

I am not very familiar with databases and the theories behind how they work. Is it any slower from a performance standpoint (inserting/updating/querying) to use Strings for Primary Keys than integers? ...

Strings and ints, implicit and explicit...

Had a coworker ask me this, and in my brain befuddled state I didn't have an answer: Why is it that you can do: string ham = "ham " + 4; But not: string ham = 4; If there's an implicit cast/operation for string conversion when you are concatenating, why not the same when assigning it as a string? (Without doing some operator overl...

Mature and Robust .NET Class to allow/disallow XHTML tags/attributes

I need an extensible class to parse a string and allow certain XHTML tags and attributes. If the given string contains invalid tags, they shall simply be encoded to display on the page as entered. I need to be assured that no user input will be lost. Thank you! ...

How can you get the height metric of a string in PostScript?

You can obtain the width of a string in the current font with stringwidth and although this actually pushes offset coordinates on the stack, the y-value always seems to be useless. Is there a way to determine the exact height of a string, that may or may not include descenders? ...

C++ function that returns string doesn't work unless there's an endl involved...?

I've got a function inside of a class that returns a string. Inside this function, I can only get it to work when I add cout<<endl to the function before the return statement. Any idea why this is, or how I can fix it? I'm running this in Eclipse on a Mac In "main.cpp": #include <iostream> #include <fstream> #include <string> #includ...

Return first match of Ruby regex

I'm looking for a way to perform a regex match on a string in Ruby and have it short-circuit on the first match. The string I'm processing is long and from what it looks like the standard way (match method) would process the whole thing, collect each match, and return a MatchData object containing all matches. match = string.match(/reg...

Is there a regular expression to find two different words in a sentence?

Is there a regular expression to find two different words in a sentence? Extra credit for an expression that works in MS Visual Studio 2008 :) For example: reg_ex_match(A, B, "A sentence with A and B") = true reg_ex_match(C, D, "A sentence with A and B") = false See also this related question ...

What's the use of System.String.Copy in .NET?

I'm afraid that this is a very silly question, but I must be missing something. Why might one want to use String.Copy(string)? The documentation says the method Creates a new instance of String with the same value as a specified String. Since strings are immutable in .NET, I'm not sure what's the benefit of using this method, a...

Split Java String in chunks of 1024 bytes

What's an efficient way of splitting a String into chunks of 1024 bytes in java? If there is more than one chunk then the header(fixed size string) needs to be repeated in all subsequent chunks. ...

C# split string but keep split chars

I'm splitting a string by three different characters but I want the output to include the characters I split by. Is there any easy way to do this? ...

Remove brackets with regular expression in C#

I want to remove square brackets from an SQL string, but only where there is no whitespace inside them. E.g. "SELECT [intId], [The Description]" should return "SELECT intId, [The Description]". I can get the square brackets without spaces inside with the regular expression: \[[^\s]*\] How can the square brackets from these matches b...

Removing accents/diacritics from string while preserving other special chars (tried mb_chars.normalize and iconv)

Hi, There is a very similar question already. One of the solutions uses code like this one: string.mb_chars.normalize(:kd).gsub(/[^x00-\x7F]/n, '').to_s Which works wonders, until you notice it also removes spaces, dots, dashes, and who knows what else. I'm not really sure how the first code works, but could it be made to strip only...

Beginner question about Caesar cipher in C++

To start off, I'm four weeks into a C++ course and I don't even know loops yet, so please speak baby talk? Okay, so I'm supposed to read a twelve character string (plus NULL makes thirteen) from a file, and then shift the letters backwards three, and then print my results to screen and file. I'm okay with everything except the shifting...