Dealing with long Strings & TextView behavior

python multiline string to single line
python long string
python multiline string format
multiline string python
python multiline string with variables
how to convert multiple lines into single line in python
line break python string
python line continuation

I’m developing an android app that gets objects from a server and shows them in a simple list.

I’m trying to figure out how to deal with long object’s titles : Every title populates a designated multi-line TextView. If a title is longer than 16 characters, it messes with my desired UI.

There are two scenarios I need to solve -

1). If the title is longer than 16 characters & contains more than one word, I need to split the words into different lines (I tried to .split("") and .trim(), but I don’t want to use another view, just break a line in the same one, and the use in ("") seems unreliable to me).

2). If the title is longer than 16 characters and contains only one long word, I only need to change font size specifically.

Any ideas for a good and reliable solution?

Thanks a lot in advance.

Code like below it will work as you need

String title; //your title

//find length of your title
int length = title.length();

if (length>16){
string[] titles = myString.split("\\s+");

int size = titles.length;

if (size < 2){
      yourTextview.setText(title);
   // reduce the text size of your textview
}else {
  String newTitle= "";
for (int i=0;i<titles.length;i++){
  newTitle = titles[i]+"\n"
}
  yourTextview.setText(newTitle);

}
}

Write a long string into multiple lines of code in Python, When using PEP8 code checkers such as flake8 in Python, an error of E501 line too long occurs when one line exceeds 80 characters.Here  Dealing with very very long string lists using Database 12.2. Keith Laker. Senior Principal Product Manager. Oracle RDBMS 11gR2 introduced the LISTAGG function for working with string values. It can be used to aggregate values from groups of rows and return a concatenated string where the values are typically separated by a comma or semi-colon - you can determine this yourself within the code by supplying your own separator symbol.

use SpannableString for a single view

For title:

 SpannableString titleSpan = new SpannableString("title String");
 titleSpan.setSpan(new RelativeSizeSpan(1.3f), 0, titleSpan.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

for Message

SpannableString messageSpan = new SpannableString("Message String");
messageSpan.setSpan(new RelativeSizeSpan(1.0f), 0, messageSpan.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

set in TextView

 tvTermsPolicyHeading.setText(TextUtils.concat(titleSpan, messageSpan));

How to write long strings in Multi-lines C/C++?, Image a situation where we want to use or print a long long string in C or C++, how to do this? In C/C++, we can break a string at any point in the middle using  I’m trying to figure out how to deal with long object’s titles : Every title populates a designated multi-line TextView. If a title is longer than 16 characters, it messes with my desired UI. There are two scenarios I need to solve - 1).

You can split and then concatenate the words using "\n" if there are more than one words. In case of long word You can see this question here Auto-fit TextView for Android

Chapter 6 – Manipulating Strings, Text is one of the most common forms of data your programs will handle. are neatly aligned, even if you aren't sure how many characters long your strings are. overflow-wrap: break-word; makes sure the long string will wrap and not bust out of the container. You might as well use word-wrap as well because as the spec says, they are literally just alternate names for each other. Some browsers support one and not the other. Firefox (tested v43) only supports word-wrap.

try this:

if(title.split(" ").size > 1){
    String line1 = title.substring(0, 16);
    int end = line1.lastIndexOf(" ");
    titleTextView.setText(title.substring(0,end) + "\n" + 
    title.substring(end+1,title.size-1);
}else{
    titleTextView.setText(title);
    titleTextView.setTextSize(yourTextSize);
}

this code should work perfectly for your case.

Python Multiline String, It can be handy when you have a very long string. You shouldn't keep such text in a single line. It kills the readability of your code. In Python, you have different  Long strings would be split to multiple lines, which would push the rows down lower. Basically, like <table> alignment. If table type alignment wasnt possible, i'd at least hope that the lines could be split to multiple lines without overrunning each other.

Long strings, You can now use Stata's string variables to hold exceedingly long strings, even the contents of files, and even binary files. 2. Identify the Cause of String Algae — The most common causes of string algae are high pH and Phosphorous (P) levels. The best way to identify what problem you are dealing with is by testing your water quality, once recognized, then you can adjust your pond chemistry based on the following measures. Lowering Your pH Levels

Write long strings with wiggly HEREDOCs, There's multiple ways to generate String literals in Ruby. If you are creating long, or multi-line, strings, the HEREDOC (or 'Here document') is  This technically works to get our output on multiple lines. However, writing a very long string on a single line will quickly become very hard to read and work with. We can use the concatenation operator to show the string on multiple lines. const threeLines = "This is a string " + "that spans across " + "three lines.";

Rust, let a = "foobar"; let b = "foo\ bar"; // `a` and `b` are equal. assert_eq!(a,b);. Break raw-string literals to separate strings, and join them with the concat! macro C and C++ have automatic concatenation of adjacent quoted strings. This means that . const char *a = "a" "b"; and. const char *b = "ab"; will make a and b point at identical data. You can of course extend this, but it becomes troublesome when the strings contain quotes. Your example seems not to, so it might be practical then.

Comments