Replace multiple space with Single space in RichTextBox
-
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
-
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
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
-
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
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 bys=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