Questions tagged [string-length]

String length most commonly refers to the number of characters contained within a string. However, it could also mean the screen space a string takes up when printed.

This tag should be used for either of the two following types of questions:

  1. Those dealing with the number of characters contained within a string.
  2. Those dealing with measuring the size of a string (in pixels, millimeters, etc.) when it is printed on a screen.
1040 questions
13
votes
3 answers

Get string length in pixels using JavaScript

I want to know exact length in pixels of String i.e. "Hello World". It should not be length of my container. Any Help???
Kundan Atre
  • 3,853
  • 5
  • 26
  • 39
13
votes
6 answers

Select string length in mongodb

How do you query mongodb to find the length of a particular string/text field? And how would you find the max length of a query set?
user1018364
  • 285
  • 1
  • 4
  • 10
13
votes
3 answers

How do I find the longest string in Python?

Something like max(len(s1), len(s2)) will only return the maximum length. But if I actually want to find out which string is longer, and perhaps save it to another string, how is that done? max(s1,s2) seems to return the string with the larger…
user1689935
  • 319
  • 2
  • 4
  • 6
12
votes
2 answers

How to sort by length and then alphabetically

Assume I had the following Javascript array. How do you sort by length, then alphabetically? Assume the following array: var array = ["a", "aaa", "bb", "bbb", "c"]; When sorted it should produce: a, c, bb, aaa, bbb. Thank you in advance!
Mike Smith
  • 145
  • 1
  • 8
12
votes
2 answers

Best Practice for Fixed Size String Class

I would like to have a fixed size string class. Ideally, the interface would match the one of std::string with the one difference that the new class never allocates new memory. It is supposed to be a handy class for application cases where…
ruhig brauner
  • 943
  • 1
  • 13
  • 35
12
votes
2 answers

R base function to sort vector of strings based on length

I was wondering if there is an already made function in R base package that can sort a vector of strings taking into consideration the length of each element and then of course the lexicographical order. For instance after a sort call on some…
Marius
  • 990
  • 1
  • 14
  • 34
12
votes
2 answers

Passing lengthy strings (as an argument) into a console application

I'm creating a console application in C# to which, at execution, it is passed a bunch of data. Three of them are short strings, such as username, password, etc. However, one of them is a rather lengthy XML document. How long can the strings be, when…
11
votes
2 answers

Reverse Array, Let Elements in New Array Equal Length of Original Array Elements - JavaScript

Trying to solve this kata on Codewars. I've been able to reverse the array into a string, but haven't been able to assign this string into individual elements of a specified length. I tried: function ultimateReverse (array) { let newArray =…
HappyHands31
  • 4,001
  • 17
  • 59
  • 109
11
votes
2 answers

Get "actual" length of string in Unicode characters

given a character like "✮" (\xe2\x9c\xae), for example, can be others like "Σ", "д" or "Λ") I want to find the "actual" length that character takes when printed onscreen for example len("✮") len("\xe2\x9c\xae") both return 3, but it should be 1
user3584604
  • 119
  • 1
  • 4
10
votes
2 answers

constexpr log10 Function for Integers

So I need log10 functionality to find the number of characters required to store a given integer. But I'd like to get it at compile time to determine the length of char arrays statically based on these integer constants defined in my code.…
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
10
votes
5 answers

How can I estimate the disk size of a string with JavaScript?

I need to try to estimate the DISK size of a text string (which could be raw text or a Base64 encoded string for an image/audio/etc) in JavaScript. I'm not sure how to estimate this. The only thing when Googling i can find is .length so i thought…
Oscar Godson
  • 31,662
  • 41
  • 121
  • 201
10
votes
4 answers

What is a surrogate pair?

I came across this code in a javascript open source project. validator.isLength = function (str, min, max) // match surrogate pairs in string or declare an empty array if none found in string var surrogatePairs =…
Noman Ur Rehman
  • 6,707
  • 3
  • 24
  • 39
10
votes
2 answers

Why "K".Length gives me wrong result?

I am seeing this strange issue, and can't find anything similar to this anywhere on the web: int l = "K".Length; //This actually returns 2 !!! The 'Autos' window in //the debugger also shows "K".Length as 2. string s =…
Christian
  • 103
  • 3
9
votes
3 answers

Go “panic: runtime error: index out of range” when the length of array is not null

I am having a hard time learning how to loop through a string in Go to do some stuff (specifically, to separate words than contain vowels). I wrote this code snippet: https://play.golang.org/p/zgDtOyq6qf. Here is the error I’m getting when running…
jiji
  • 337
  • 2
  • 3
  • 13
9
votes
1 answer

Internet Explorer Returning Wrong Length of String

I've ran into a possible bug with IE where calling the JavaScript .length function returns a value that is off by 1 if/when the string was derived from .toLocaleString(). var d = new Date(); var locale = navigator.language; var month =…
Jed
  • 10,649
  • 19
  • 81
  • 125