Given a C++ std::string
variable which includes tab characters, is it possible to determine the length of that string as it would appear on the "screen"? i.e.:
std::string var = "\t\t\t";
std::cout << var.length(); // result: 3
std::cout << printed_length(var); // result: 3*(# of spaces per tab)
When dealing with C++ strings (std::string), you're looking for length() or size(). Both should provide you with the same value. However when dealing with C-Style strings, you would use strlen(). Save this answer.
The default value for the tab-size property is 8 space characters, and it can accept any positive integer value.
The Java String length() method is a method that is applicable for string objects. length() method returns the number of characters present in the string. The length() method is suitable for string objects but not for arrays. The length() method can also be used for StringBuilder and StringBuffer classes.
This function is used to convert the numerical value to the wide string i.e. it parses a numerical value of datatypes (int, long long, float, double ) to a wide string. It returns a wide string of data type wstring representing the numerical value passed in the function.
Not easily. It's impossible without specific knowledge of the "screen" involved (really, the software driving the output), because tab expansion varies so widely. There are four fairly obvious possibilities, based on fixed expansion vs. expansion to a multiple of something, and based on character cells vs. some other fixed measurement (e.g., for proportional fonts). There are also "smart tabs" with even more complex criteria, where one tab's expansion may depend upon another tab.
On a typical "console" that'll be expansion mod 8 character cells. To deal with that, you'll not only have to count the tabs, but also look at the position of each tab in the string. You'll also have to make some assumptions (or provide a parameter) about the position of the beginning of the string relative to a tab stop.
Bottom line: if you want to do something like this, you'll have to do it yourself, based on knowledge of how tabs will be expanded on your target.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With