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
23
votes
5 answers

Counting characters in golang string

I am trying to count "characters" in go. That is, if a string contains one printable "glyph", or "composed character" (or what someone would ordinarily think of as a character), I want it to count 1. For example, the string "Hello, 世界", should count…
Bjorn Roche
  • 11,279
  • 6
  • 36
  • 58
22
votes
3 answers

Best way to get length of const char * in c++

i know two way's to get length of const char * const char * str = "Hello World !"; int Size = 0; while (str[Size] != '\0') Size++; and other way is very simple const char * str = "Hello World !"; size_t Size = strlen(str); but i don't want to use…
JamesAlb
  • 263
  • 1
  • 3
  • 7
22
votes
4 answers

Remove Element from Set

I'm trying to remove all Strings that are of even length in a set. Here is my code so far, but I am having trouble getting the index from the iterator in the enhanced-for-loop. public static void removeEvenLength(Set list) { for (String…
f3d0r
  • 541
  • 3
  • 12
  • 27
21
votes
5 answers

How to remove a row from pandas dataframe based on the number of elements in a column

In the following pandas.DataFframe: df = alfa beta ceta a,b,c c,d,e g,e,h a,b d,e,f g,h,k j,k c,k,l f,k,n How to drop the rows in which the column values for alfa has more than 2 elements? This can be done using…
everestial007
  • 6,665
  • 7
  • 32
  • 72
19
votes
1 answer

Get column value length, not column max length of value

How do I get actual length of value in column? My (oracle) sql command returns maximum length of value that can be inserted in the column instead of real length of value. How to fix this? SQL> SELECT typ, length(t1.typ) FROM AUTA_VIEW t1; TYP …
Buksy
  • 11,571
  • 9
  • 62
  • 69
18
votes
6 answers

How can I truncate a line of text longer than a given length?

How would you go about removing everything after x number of characters? For example, cut everything after 15 characters and add ... to it. This is an example sentence should turn into This is an exam...
undefinedChar
  • 537
  • 1
  • 5
  • 18
18
votes
5 answers

use length function in substring in spark

I am trying to use the length function inside a substring function in a DataFrame but it gives error val substrDF = testDF.withColumn("newcol", substring($"col", 1, length($"col")-1)) below is the error error: type mismatch; found :…
satish
  • 193
  • 1
  • 1
  • 6
18
votes
6 answers

Len() function vs String.Length property; which to choose?

I'm making the transition from VB6 to VB.Net (VS 2010) and have a basic rather than expansive understanding of the latter. I obviously have quite a bit of code to... I hesitate to use the word "upgrade" when "port" would be more apt given that the…
Alan K
  • 1,957
  • 3
  • 19
  • 30
17
votes
4 answers

Which is faster C++ String length() or size()?

length() returns the number of characters in the string and size() returns a size_t which is also the same but used to make it consistent with other STL containers. For computing length(), the string iterates through all the characters and counts…
ronilp
  • 455
  • 2
  • 9
  • 25
17
votes
1 answer

Automatic adjustment of margins in horizontal bar chart

I need to produce a series of horizontal grouped bar charts. The barplot function does not automatically adjust the margins of the plot, therefore the text gets cut off. graphics.off() # close graphics windows test <- matrix(c(55,65,30,…
Max C
  • 2,573
  • 4
  • 23
  • 28
16
votes
4 answers

Timestamp string length

If I did this // Default implementation of UNIX time of the current UTC time TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0); string myResult = ""; myResult = Convert.ToInt64(ts.TotalSeconds).ToString(); What is the maximum…
001
  • 62,807
  • 94
  • 230
  • 350
16
votes
4 answers

Finding field with longest length in a column

How do I find the field with the longest length of a specific column in a MySQL table?
Lizard
  • 43,732
  • 39
  • 106
  • 167
16
votes
4 answers

Reading a character string of unknown length

I have been tasked with writing a Fortran 95 program that will read character input from a file, and then (to start with) simply spit it back out again. The tricky part is that these lines of input are of varying length (no maximum length given) and…
user2053072
15
votes
2 answers

Adding a DataFrame column with len() of another column's values

I'm having a problem trying to get a character count column of the string values in another column, and haven't figured out how to do it efficiently. for index in range(len(df)): df['char_length'][index] = len(df['string'][index])) This…
halycos
  • 305
  • 2
  • 5
14
votes
5 answers

How to return all list elements of a given length?

I'm trying to return words that have a specific length. This is my code so far. words is a list and size is a positive integer. def by_size(words, size) for word in words: if len(word) == size: I'm not sure how to continue.…
shaarr
  • 141
  • 1
  • 1
  • 4
1 2
3
69 70