Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Replace multiple space with Single space in RichTextBox

Replace multiple space with Single space in RichTextBox

Scheduled Pinned Locked Moved Visual Basic
helpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rupesh Kumar Swami
    wrote on last edited by
    #1

    hi everyone, i want to know whether there r any method or Trick to replace multiple spaces with single space.Let me explain i load a text file in richtextbox.This file contain a number of lines. Now within two words of a single line there are single space(mean space(1)),double space(mean space(2)),tripple space(mean space(3)).... multiple space(mean space(n)). Now i want to Replace all occurence of multiple type of Space with Single space. I think i properly told my problem. anybody have idea what should i do?

    Rupesh Kumar Swami Software Engineer, Integrated Solution, Bikaner (India) My Company

    C L 2 Replies Last reply
    0
    • R Rupesh Kumar Swami

      hi everyone, i want to know whether there r any method or Trick to replace multiple spaces with single space.Let me explain i load a text file in richtextbox.This file contain a number of lines. Now within two words of a single line there are single space(mean space(1)),double space(mean space(2)),tripple space(mean space(3)).... multiple space(mean space(n)). Now i want to Replace all occurence of multiple type of Space with Single space. I think i properly told my problem. anybody have idea what should i do?

      Rupesh Kumar Swami Software Engineer, Integrated Solution, Bikaner (India) My Company

      C Offline
      C Offline
      Chatura Dilan
      wrote on last edited by
      #2

      hi, May be My Article[^] will help you if you do not found a correct solution, but you will have to change it little bit.

      Chatura Dilan

      1 Reply Last reply
      0
      • R Rupesh Kumar Swami

        hi everyone, i want to know whether there r any method or Trick to replace multiple spaces with single space.Let me explain i load a text file in richtextbox.This file contain a number of lines. Now within two words of a single line there are single space(mean space(1)),double space(mean space(2)),tripple space(mean space(3)).... multiple space(mean space(n)). Now i want to Replace all occurence of multiple type of Space with Single space. I think i properly told my problem. anybody have idea what should i do?

        Rupesh Kumar Swami Software Engineer, Integrated Solution, Bikaner (India) My Company

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        Hi, remark: I will use - to indicate a space 1. in a string s the statement s=s.Replace("--","-") would replace every pair of spaces by a single space; so 7 spaces would become 4 spaces. 2. if you redo step 1 the number of spaces would be further reduced; you could loop over 1. until the length of s no longer changes. 3. you can apply the above to myRichTextBox.Rtf With the above, you would have fewer than 10 lines of code to remove all multiple spaces. BTW: if you want to leave double spaces as is, replace step 1 by s=s.Replace("---","--") :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups