16 Matching Annotations
  1. Sep 2020
      • A String is a sequence of character.you can access the character using bracket operator.
      • In string the expression in brackets is called index it calculates the character from 0.
      • In index we can do operations and if it is not in integer it gives you error.
      • Len means it is a built in function that returns the number of characters in the string.
      • A lot of computations involve processing a string and while doing it will do from beginning with each and every string.it is known as traversal wit for loop in string.
      • String slice means we can divide a word into two and we can do concatenation.
      • In string we cannot use some operators we can only use some operators like in, as,etc.
      • . String is immutable we cannot change .
    1. Chapter

      Strings Strings are sequence of characters and zero-index based. A char in a string can be accessed by using []. A string can be traversed using for loop. Strings can be sliced to get a piece of string. Various built in methods area available such as len,find,lower,upper,capitalize,isalpha,isnumeric etc.

      operator concats two strings. comparison operators compares the strings lexcographically. Most importantly strings are immutable once created they can't be modified.

    2. *A string is a sequence , which means it is an ordered collection of other values.

      • You can access the characters one at a time with the bracket operator:
               fruit            =
        

        ' banana ' letter = fruit[1] The second statement selects character number 1 from fruit and assigns it to letter . The expression in brackets is called an index .A lot of computations involve processing a string one character at a time. Often they start at the beginning, select each character in turn, do something to it, and continue until the end. This pattern of processing is called a traversal A segment of a string is called a slice . Selecting a slice is similar to selecting a character: s = ' Monty Python ' s[0:5] ' Monty ' s[6:12] ' PythonIt is tempting to use the [] operator on the left side of an assignment, with the intention of changing a character in a string. For example: greeting = ' Hello, world! ' greeting[0] = ' J ' TypeError: ' str ' object does not support item assignment The “object” in this case is the string and the “item” is the character you tried to assign. For now, an object is the same thing as a value, but we will refine that definition later (Section 10.10). The reason for the error is that strings are immutable ,

  2. Jul 2020
  3. Jun 2020
  4. May 2020
  5. Mar 2020
    1. Then there’s markup inside each paragraph, like links and such. You could do it right in the translation strings, but your translator then needs to know how to handle the markup, and you risk duplicating knowledge if you go as far as to hard-code link URLs. What I do is split up the translations, but keep them under the same key: en.yml1 2 3 4 log_in_or_sign_up: text: "%{log_in} or %{sign_up} to do stuff." log_in: "Log in" sign_up: "Sign up" header.erb1 2 3 4 5 <%= t( :'log_in_or_sign_up.text', log_in: link_to(t(:'log_in_or_sign_up.log_in'), login_path), sign_up: link_to(t(:'log_in_or_sign_up.sign_up'), signup_path) ) %> This way, the translator sees no code or markup (except for the i18n interpolation syntax) and there is no duplication.
    2. You probably don’t want one translation key per sentence, though. It’s helpful for the translator to have context rather than a lot of short strings, and less fiddly on your part.
  6. Jul 2019