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. C#
  4. Writing a Text in StreamWriter such that alignment should be proper for different languages ( like English, Chinise, German...etc).

Writing a Text in StreamWriter such that alignment should be proper for different languages ( like English, Chinise, German...etc).

Scheduled Pinned Locked Moved C#
announcement
5 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.
  • P Offline
    P Offline
    Piyush Vaishnav
    wrote on last edited by
    #1

    Hi All, I am writing text into StreamWriter by sw.Write("Text coming from Labels : so can be in english or chinese or any other languages") method. After writing first text, I am adding tabs and then adding second text. Now adding a new line and adding first text + tabs + second text. It looks like this: Model :\t \t \t \t \t XXXX Version :\t \t \t \t YYYY Note : I am not able to put white spaces here so just putted \t. Assume that the first X and first Y starting position is equal. Alignment is coming properly for English. But if the input texts are in Chinese then it comes like this : Model :\t \t \t \t \t XXXX Version :\t \t \t \t YYYY Here YYYY is not coming just below XXXX such that the start position of first X and first Y should be same, This Tab spaces are the same for different languages. I want atleast alignment should be proper with every languages. Thanks in Advance.. Piyush Vaishnav

    L T 2 Replies Last reply
    0
    • P Piyush Vaishnav

      Hi All, I am writing text into StreamWriter by sw.Write("Text coming from Labels : so can be in english or chinese or any other languages") method. After writing first text, I am adding tabs and then adding second text. Now adding a new line and adding first text + tabs + second text. It looks like this: Model :\t \t \t \t \t XXXX Version :\t \t \t \t YYYY Note : I am not able to put white spaces here so just putted \t. Assume that the first X and first Y starting position is equal. Alignment is coming properly for English. But if the input texts are in Chinese then it comes like this : Model :\t \t \t \t \t XXXX Version :\t \t \t \t YYYY Here YYYY is not coming just below XXXX such that the start position of first X and first Y should be same, This Tab spaces are the same for different languages. I want atleast alignment should be proper with every languages. Thanks in Advance.. Piyush Vaishnav

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

      a text file contains text, not formatting. the only way to give it some columnar layout without using a command language, is by inserting the right number of spaces and using a non-proportional (i.e. monospaced) font, such as Courier New. I expect there isn't a non-proportional font for Chinese. Using tabs to replace spaces could work also, there may be some issues. And it is a first step towards a command language. Real command languages would be HTML, RTF, PostScript, etc. In summary, there is no general solution IMO. :)

      Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

      1 Reply Last reply
      0
      • P Piyush Vaishnav

        Hi All, I am writing text into StreamWriter by sw.Write("Text coming from Labels : so can be in english or chinese or any other languages") method. After writing first text, I am adding tabs and then adding second text. Now adding a new line and adding first text + tabs + second text. It looks like this: Model :\t \t \t \t \t XXXX Version :\t \t \t \t YYYY Note : I am not able to put white spaces here so just putted \t. Assume that the first X and first Y starting position is equal. Alignment is coming properly for English. But if the input texts are in Chinese then it comes like this : Model :\t \t \t \t \t XXXX Version :\t \t \t \t YYYY Here YYYY is not coming just below XXXX such that the start position of first X and first Y should be same, This Tab spaces are the same for different languages. I want atleast alignment should be proper with every languages. Thanks in Advance.. Piyush Vaishnav

        T Offline
        T Offline
        TheyCallMeMrJames
        wrote on last edited by
        #3

        Much as Luc said, your choices are either to use delimiters (or markup), or to go to fixed-width columns. You can use string.PadLeft or .PadRight to achieve columns, but you'll need to know the maximum length possible in each column (or truncate longer data). It's not good to try to store your formatting in with your data, I would recommend delimited text or finding a solution via XML and finally using something to generate your display (rather than relying intrinsically on the stored data). Cheers.

        My Latest: How quickly is the Government spending your money? Tech blog: They Call me Mister James

        P 1 Reply Last reply
        0
        • T TheyCallMeMrJames

          Much as Luc said, your choices are either to use delimiters (or markup), or to go to fixed-width columns. You can use string.PadLeft or .PadRight to achieve columns, but you'll need to know the maximum length possible in each column (or truncate longer data). It's not good to try to store your formatting in with your data, I would recommend delimited text or finding a solution via XML and finally using something to generate your display (rather than relying intrinsically on the stored data). Cheers.

          My Latest: How quickly is the Government spending your money? Tech blog: They Call me Mister James

          P Offline
          P Offline
          Piyush Vaishnav
          wrote on last edited by
          #4

          Hi, Now I used string.PadRight(40, ' ') for the first text and then after adding second text. It's working fine for english. But for Chinese still second text is not coming below the First Row's second text.

          T 1 Reply Last reply
          0
          • P Piyush Vaishnav

            Hi, Now I used string.PadRight(40, ' ') for the first text and then after adding second text. It's working fine for english. But for Chinese still second text is not coming below the First Row's second text.

            T Offline
            T Offline
            TheyCallMeMrJames
            wrote on last edited by
            #5

            Are you adding the required line breaks? If you reveal a bit of your code it might help others solve the problem. As previously stated, you're going to have a hard time finding a balance of content and format. Once, there was this whole thing about HTML and CSS, and then, this other time, XML and XSL/T...

            My Latest: How quickly is the Government spending your money? Tech blog: They Call me Mister James

            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