Results 1 to 6 of 6

Thread: replace the character "thin space" in a textfile

  1. #1

    Thread Starter
    Hyperactive Member fabianus's Avatar
    Join Date
    Sep 2004
    Location
    Paris
    Posts
    402

    Question replace the character "thin space" in a textfile

    Hallo guys,

    I would like to replace the character „thin space” (see http://www.fileformat.info/info/unic...2009/index.htm) in a text file to normal space (" ").
    What I thought to do is :

    Dim myResultString as string = replace(mySourceString, XXXXX, " ")

    The problem is that I do not know how to produce the "thin space" at the place of the XXXXX in my code.

    Thank you very much for any help!

    Regards,
    Fabian

  2. #2
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: replace the character "thin space" in a textfile

    VB Code:
    1. mySourceString = mySourceString.Replace(Convert.ToChar(2009)," "c)

  3. #3

    Thread Starter
    Hyperactive Member fabianus's Avatar
    Join Date
    Sep 2004
    Location
    Paris
    Posts
    402

    Re: replace the character "thin space" in a textfile

    Hello Wild Bill !

    Thank you very much for your solution !
    I have one more difficulty : In fact the character I would like to replace is not replaced. Perhaps because it is not the "thin space" character. To check this out I would like to get its Unicode number (right name?), so see if it is 2009. Could you help me once more for this?

    Thank you very much!

    Regards,
    Fabian

  4. #4
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: replace the character "thin space" in a textfile

    If you have a word processor that you can view the file in hex format, you could find out. I think ultraedit has a freeware version that allows you to do that. If you post the file as an attachment, I can look at it.

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,433

    Re: replace the character "thin space" in a textfile

    Or you can just read the file into a string and get the code for each character in VB:
    VB Code:
    1. Dim file As New IO.StreamReader(filePath)
    2.         Dim fileContents As String = file.ReadToEnd()
    3.  
    4.         For i As Integer = 0 To fileContents.Length - 1 Step 1
    5.             If MessageBox.Show(String.Format("Index: {1}{0}Character: {2}{0}Unicode Value: {3}", _
    6.                                              Environment.NewLine, _
    7.                                              i, _
    8.                                              fileContents.Chars(i), _
    9.                                              Convert.ToInt32(fileContents.Chars(i))), _
    10.                                "Character Code", _
    11.                                MessageBoxButtons.OKCancel, _
    12.                                MessageBoxIcon.Information) = Windows.Forms.DialogResult.Cancel Then
    13.                 Exit For
    14.             End If
    15.         Next i
    Let the loop run until it gets to the first instance of the character you want to replace and it will give you its Unicode value.

  6. #6

    Thread Starter
    Hyperactive Member fabianus's Avatar
    Join Date
    Sep 2004
    Location
    Paris
    Posts
    402

    Re: replace the character "thin space" in a textfile

    Hey jmcilhinney,

    thank you very much! That's just perfect!

    Best regards,
    Fabian

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width