Trimming (computer programming)

In computer programming, trimming (trim) or stripping (strip) is a string manipulation in which leading and trailing whitespace is removed from a string.

For example, the string (enclosed by apostrophes)

would be changed, after trimming, to

Variants

Definition of whitespace

The characters which are considered whitespace varies between programming languages and implementations. For example, C traditionally only counts space, tab, line feed, and carriage return characters, while languages which support Unicode typically include all Unicode space characters. Some implementations also include ASCII control codes (non-printing characters) along with whitespace characters.

Java's trim method considers ASCII spaces and control codes as whitespace, contrasting with the Java isWhitespace() method, which recognizes all Unicode space characters.

Delphi's Trim function considers characters U+0000 (NULL) through U+0020 (SPACE) to be whitespace.

Usage

Following are examples of trimming a string using several programming languages. All of the implementations shown return a new string and do not alter the original variable.

Trim (computing)

A Trim command (known as TRIM in the ATA command set, and UNMAP in the SCSI command set) allows an operating system to inform a solid-state drive (SSD) which blocks of data are no longer considered in use and can be wiped internally.

Trim was introduced soon after SSDs were introduced. Because low-level operation of SSDs differs significantly from hard drives, the typical way in which operating systems handle operations like deletes and formats resulted in unanticipated progressive performance degradation of write operations on SSDs. Trimming enables the SSD to handle garbage collection overhead, which would otherwise significantly slow down future write operations to the involved blocks, in advance.

Although tools to "reset" some drives to a fresh state were already available before the introduction of trimming, they also delete all data on the drive, which makes them impractical to use for ongoing optimization. By 2014 many SSDs had internal idle/background garbage collection mechanisms that work independently of trimming; although this successfully maintains their performance even under operating systems that do not support Trim, it has the associated drawbacks of increased write amplification and wear of the flash cells.

Draft (hull)

The draft (American) or draught (British) of a ship's hull is the vertical distance between the waterline and the bottom of the hull (keel), with the thickness of the hull included; in the case of not being included the draft outline would be obtained. Draft determines the minimum depth of water a ship or boat can safely navigate. The draft can also be used to determine the weight of the cargo on board by calculating the total displacement of water and then using Archimedes' principle. A table made by the shipyard shows the water displacement for each draft. The density of the water (salt or fresh) and the content of the ship's bunkers has to be taken into account. The closely related term "trim" is defined as the difference between the forward and aft drafts.

Drafts of a ship

  • The draft aft (stern) is measured in the perpendicular of the stern.
  • The draft forward (bow) is measured in the perpendicular of the bow.
  • The mean draft is obtained by calculating from the averaging of the stern and bow drafts, with correction for water level variation and value of the position of F with respect to the average perpendicular.
  • Jun (musician)

    Jun (stylized as JUN, born in Kobe, Hyōgo) is a Japanese visual kei rock musician and singer-songwriter. He is currently the guitarist of GOTCHAROCKA. Previously he was in the bands Se'lavy, Mar'derayla and Phantasmagoria, Spiv States (stylized as SPIV STATES and previously as spiv states) and released solo material under the alias Attic (stylized as attic) and under his own name.

    Band history

    Se'lavy and Mar'derayla

    Jun's first known band was Se'lavy. Not much is known about them except that Iori was also in the group. His second band Mar'derayla formed in 2002 and were signed to Under Code Production, a sublabel of Free-Will run by Jun's future bandmate Kisaki. The group also contained Iori on guitar, Hayato on vocals, Hagane on bass and Rui on drums. Their debut mini-album Kiseki... Ring was released in May 2003, Rui left soon after and was replaced by Toki in June. They announced they would be disbanding after the release of "Love & Peace & Horror" on March 10, 2004, but officially disbanded on August 1.

    Jun (given name)

    Jun (じゅん, ジュン, 준) is a very common Japanese or Korean given name used by either sex.

    Possible writings

    Jun can be written using different kanji characters and can mean:

  • 純, "genuine/pure"
  • 潤, "moisture"
  • 淳, "pure/genuine"
  • 順, "obey"
  • 準, "conform to/consult with"
  • 洵, "truth"
  • 隼, "falcon"
  • The name can also be written in hiragana or katakana.

    People

  • Jun (musician), a Japanese musician
  • Jun Akiyama (準, born 1969), a Japanese professional wrestler
  • Jun Aoyama (隼, born 1988), Japanese football player
  • Jun Ashida (淳, born 1930), Japanese fashion designer
  • Jun Azumi (淳, born 1962), Japanese politician
  • Jun Etō (淳, 1933–1999), Japanese literary critic
  • Jun Fan (振, 1940–1973), Martial artist, actor, philosopher
  • Jun Fubuki (ジュン, born 1952), Japanese actress
  • Jun Fukuda (純, 1923–2000), Japanese director
  • Jun Fukuyama (潤, born 1978), Japanese voice actor
  • Jun Hayashi (潤, born 1972), Japanese politician
  • Jun Ichikawa (準, 1948–2008), Japanese film director and screenwriter
  • Jun Ishikawa (author) (淳, 1899–1987), Japanese author, translator and literary critic
  • June 2

    June 2 is the 153rd day of the year (154th in leap years) in the Gregorian calendar. There are 212 days remaining until the end of the year.

    Events

  • 455 Sack of Rome: Vandals enter Rome, and plunder the city for two weeks
  • 1010 The Battle of Aqbat al-Bakr took place in the context of the Fitna of al-Andalus resulting in a defeat for the Caliphate of Córdoba.
  • 1098 First Crusade: The first Siege of Antioch ends as Crusader forces take the city. The second siege would later start on June 7.
  • 1615 The first Récollet missionaries arrive at Quebec City, from Rouen, France.
  • 1676 Franco-Dutch War: France ensured the supremacy of its naval fleet for the remainder of the war with its victory in the Battle of Palermo.
  • 1692 Bridget Bishop is the first person to go to trial in the Salem witch trials in Salem, Massachusetts. Found guilty, she is hanged on June 10.
  • 1763 Pontiac's Rebellion: At what is now Mackinaw City, Michigan, Chippewas capture Fort Michilimackinac by diverting the garrison's attention with a game of lacrosse, then chasing a ball into the fort.
  • Podcasts:

    PLAYLIST TIME:

    Latest News for: trim jun

    Int'l Horticulture Goyang Korea to be held in S. Korea

    Xinhua 24 Apr 2025
    (Photo by Jun Hyosang/Xinhua). Workers trim the plants during a media preview of International Horticulture Goyang Korea, an international flower exhibition, in Goyang, Gyeonggi Province of South Korea, on April 24, 2025.
    • 1
    ×