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.
930 questions
496
votes
8 answers

Length of string in bash

How do you get the length of a string stored in a variable and assign that to another variable? myvar="some string" echo ${#myvar} # 11 How do you set another variable to the output 11?
AJP
  • 21,889
  • 17
  • 76
  • 108
401
votes
7 answers

What is the string length of a GUID?

I want to create a varchar column in SQL that should contain N'guid' while guid is a generated GUID by .NET (Guid.NewGuid) - class System.Guid. What is the length of the varchar I should expect from a GUID? Is it a static length? Should I use…
Shimmy Weitzhandler
  • 92,920
  • 119
  • 388
  • 596
371
votes
6 answers

How to find the length of a string in R

How to find the length of a string (number of characters in a string) without splitting it in R? I know how to find the length of a list but not of a string. And what about Unicode strings? How do I find the length (in bytes) and the number of…
Igor Chubin
  • 51,940
  • 8
  • 108
  • 128
325
votes
6 answers

MySQL - How to select data by string length

SELECT * FROM table ORDER BY string_length(column); Is there a MySQL function to do this (of course instead of string_length)?
Gal
  • 20,759
  • 30
  • 92
  • 114
250
votes
10 answers

How do you get the length of a string?

How do you get the length of a string in jQuery?
RubbleFord
  • 7,006
  • 9
  • 46
  • 77
221
votes
9 answers

Why does Python code use len() function instead of a length method?

I know that python has a len() function that is used to determine the size of a string, but I was wondering why it's not a method of the string object. Update Ok, I realized I was embarrassingly mistaken. __len__() is actually a method of a string…
fuentesjr
  • 45,682
  • 27
  • 72
  • 79
166
votes
6 answers

How to get the size of a string in Python?

For example, I get a string: str = "please answer my question" I want to write it to a file. But I need to know the size of the string before writing the string to the file. What function can I use to calculate the size of the string?
babykick
  • 1,743
  • 2
  • 11
  • 7
162
votes
7 answers

How to get the number of characters in a string

How can I get the number of characters of a string in Go? For example, if I have a string "hello" the method should return 5. I saw that len(str) returns the number of bytes and not the number of characters so len("£") returns 2 instead of 1 because…
Ammar
  • 3,640
  • 6
  • 25
  • 27
118
votes
12 answers

How to get the number of characters in a std::string?

How should I get the number of characters in a string in C++?
Elliot
  • 5,828
  • 11
  • 40
  • 55
97
votes
10 answers

Retrieve the maximum length of a VARCHAR column in SQL Server

I want to find the longest VARCHAR in a specific column of a SQL Server table. Here's an example: ID = INT IDENTITY DESC = VARCHAR(5000) ID | Desc ---|----- 1 | a 2 | aaa 3 | aa What's the SQL to return 3? Since the longest value is 3…
Milo LaMar
  • 1,778
  • 1
  • 12
  • 25
97
votes
5 answers

Calculate the display width of a string in Java

How to calculate the length (in pixels) of a string in Java? Preferable without using Swing. EDIT: I would like to draw the string using the drawString() in Java2D and use the length for word wrapping.
eflles
  • 5,890
  • 10
  • 38
  • 54
91
votes
12 answers

Display only 10 characters of a long string?

How do I get a long text string (like a querystring) to display a maximum of 10 characters, using JQuery? Sorry guys I'm a novice at JavaScript & JQuery :S Any help would be greatly appreciated.
Nasir
  • 4,275
  • 8
  • 30
  • 38
87
votes
5 answers

String field value length in mongoDB

The data type of the field is String. I would like to fetch the data where character length of field name is greater than 40. I tried these queries but returning error. 1. db.usercollection.find( {$where: "(this.name.length >…
SURYA GOKARAJU
  • 1,025
  • 2
  • 8
  • 7
83
votes
8 answers

SQL Server 2008 Empty String vs. Space

I ran into something a little odd this morning and thought I'd submit it for commentary. Can someone explain why the following SQL query prints 'equal' when run against SQL 2008. The db compatibility level is set to 100. if '' = ' ' print…
jhale
  • 1,664
  • 2
  • 14
  • 21
61
votes
5 answers

Measure string size in Bytes in php

I am doing a real estate feed for a portal and it is telling me the max length of a string should be 20,000 bytes (20kb), but I have never run across this before. How can I measure byte size of a varchar string. So I can then do a while loop to trim…
Liam Bailey
  • 5,691
  • 3
  • 30
  • 44
1
2 3
61 62