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
66
votes
3 answers

java.util.UUID.randomUUID().toString() length

Does java.util.UUID.randomUUID().toString() length always equal to 36? I was not able to find info on that. Here it is said only the following: public static UUID randomUUID() Static factory to retrieve a type 4 (pseudo randomly generated) UUID.…
Yaroslav
  • 1,325
  • 1
  • 11
  • 23
58
votes
5 answers

How to force Ruby string to n characters

How to force Ruby string variable output using puts to n characters so that if the variable is longer, it will be truncated, if shorter, it will be expanded by trailing or leading spaces? Is there some standard method to do this?
Paul
  • 25,812
  • 38
  • 124
  • 247
55
votes
8 answers

SQL SELECT everything after a certain character

I need to extract everything after the last '=' (http://www.domain.com?query=blablabla - > blablabla) but this query returns the entire strings. Where did I go wrong in here: SELECT RIGHT(supplier_reference, CHAR_LENGTH(supplier_reference) -…
popkutt
  • 949
  • 3
  • 10
  • 19
51
votes
2 answers

How do I define Sequelize.STRING length?

I want to define a length of a datatype in sequelize. There is my source code : var Profile = sequelize.define('profile', { public_id: Sequelize.STRING, label: Sequelize.STRING }) It create a table profiles with a public_id with a datatype…
gusera2334967
  • 511
  • 1
  • 4
  • 3
40
votes
6 answers

PHP shortest/longest string length in array

I have an array like this $data = array( "163", "630", "43", "924", "4", "54" ); How can I select the smallest and largest values from it according to string length NOT number value. (for this example it is 1 (smallest) and…
Mark Lalor
  • 7,820
  • 18
  • 67
  • 106
37
votes
2 answers

Select rows from database by strlen

Is there a way to select database table rows where a given value is a certain length, for example, less than 5 chars long? In PHP that would be strlen. Is there anything similar in MySQL?
santa
  • 12,234
  • 49
  • 155
  • 255
36
votes
4 answers

DataAnnotations StringLength Attribute MVC - without max value

I am using Data Annotations for Model validation in MVC4 and am currently using the StringLengthAttribute however i do NOT want to specify a maximum value (currently set at 50) but DO want to specify a minimum string length value. Is there a way to…
Mr-DC
  • 799
  • 5
  • 14
  • 25
33
votes
13 answers

Java substring: 'String index out of range'

I guess I'm getting this error because the string is trying to substring a null value. But wouldn't the ".length() > 0" part eliminate that issue? Here is the Java snippet: if (itemdescription.length() > 0) { pstmt2.setString(3,…
phill
  • 13,434
  • 38
  • 105
  • 141
29
votes
3 answers

Does Java's toLowerCase() preserve original string length?

Assume two Java String objects: String str = ""; String strLower = str.toLowerCase(); Is it then true that for every value of the expression str.length() == strLower.length() evaluates to true? So, does String.toLowerCase()…
MicSim
  • 26,265
  • 16
  • 90
  • 133
27
votes
3 answers

Why does std::string("\x00") report length of 0?

I have a function which needs to encode strings, which needs to be able to accept 0x00 as a valid 'byte'. My program needs to check the length of the string, however if I pass in "\x00" to std::string the length() method returns 0. How can I get…
Adamski
  • 3,585
  • 5
  • 42
  • 78
26
votes
6 answers

Split string by length in Golang

Does anyone know how to split a string in Golang by length? For example to split "helloworld" after every 3 characters, so it should ideally return an array of "hel" "low" "orl" "d"? Alternatively a possible solution would be to also append a…
Fernando Parra
  • 357
  • 1
  • 3
  • 3
25
votes
8 answers

Is using strlen() in the loop condition slower than just checking for the null character?

I have read that use of strlen is more expensive than such testing like this: We have a string x 100 characters long. I think that for (int i = 0; i < strlen(x); i++) is more expensive than this code: for (int i = 0; x[i] != '\0'; i++) Is it true?…
user466534
25
votes
12 answers

PHP - Get length of digits in a number

I would like to ask how I can get the length of digits in an Integer. For example: $num = 245354; $numlength = mb_strlen($num); $numlength should be 6 in this example. Somehow I can't manage it to work? Thanks EDIT: The example code above --^ and…
supersize
  • 13,764
  • 18
  • 74
  • 133
25
votes
4 answers

PHP: what's the total length of a $_POST global variable?

I was wondering if anybody knows the total length that a post global could be. e.g: $_POST['formInput'] = "hello world, how long can I be?"; I am creating a site where someone will enter an unknown amount of chars into a textarea, so potentially it…
phpNutt
  • 1,529
  • 7
  • 23
  • 40
24
votes
2 answers

MySQL : strange LENGTH() behaviour on utf8 string

I am doing unit tests on requests generators, and I get in trouble with LENGTH function. I have 2 requests that follows each other : SHOW VARIABLES LIKE '%character%' Returns the following result : array(8) { [0] => array(2) { …
Alain Tiemblo
  • 36,099
  • 17
  • 121
  • 153
1
2
3
69 70