Sonderzeichen werden richtig geschrieben, aber dann falsch ausgelesen

  • VB.NET
  • .NET (FX) 4.5–4.8

Es gibt 8 Antworten in diesem Thema. Der letzte Beitrag () ist von Eierlein.

    Sonderzeichen werden richtig geschrieben, aber dann falsch ausgelesen

    Moin,

    ich bin gerade dabei ein kleines Programm zum Verwalten eines Stundenplans zu schreiben. Klappt bis jetzt fast alles so, wie ich es will, aber diese Sonderzeichen machen mir zu schaffen.
    Ich habe bereits das Problem gelöst, dass Sonderzeichen nicht richtig ausgelesen werden. Dies habe ich mit diesem Beitrag gelöst. Wenn ich jetzt aber ein Sonderzeichen in eine Textbox eingebe, wird es zwar richtig gespeichert,
    aber wenn ich es dann im Programm wieder auslesen lasse, erhalte ich nur komische Zeichen an der Stelle des Sonderzeichens. Wenn ich in der Textdatei das Sonderzeichen einmal lösche und wieder hinschreibe, wird es aber wieder
    perfekt ausgelesen. Also schließe ich daraus, dass der Fehler beim Schreiben entstehen muss (Korrigiert mich, wenn dies nicht so ist). Also habe ich versucht, das Problem genauso zu lösen, wie ich es beim Lesen auch getan habe.
    Dies habe ich mit dem kleinen Code hier gelöst

    VB.NET-Quellcode

    1. System.Text.Encoding.UTF7​

    Das bringt mir aber auch nichts...
    Spoiler anzeigen
    ​Code zum Schreiben:

    VB.NET-Quellcode

    1. ​sw.WriteLine("1: " + textSub1_mo.Text, System.Text.Encoding.UTF7)

    Code zum Lesen:

    VB.NET-Quellcode

    1. ​For Each line In IO.File.ReadAllLines(plan_dir + "\Montag.txt", System.Text.Encoding.UTF7)
    2. If line.StartsWith("1: ") Then
    3. textSub1_mo.Text = line.Replace("1: ", "")

    Kann mir hier jemand behilflich sein?

    Liebe Grüße
    Ich kam, sah und vergaß, was ich vorhatte.
    Alles n bisken wenig vorgegebener Code, um ihn zu verbessern oder den Fehler zu finden, aber ich komm auch ohne irgendeine Codierungsangabe klar:

    VB.NET-Quellcode

    1. Private Sub LoadButton_Click(sender As System.Object, e As System.EventArgs) Handles LoadButton.Click
    2. TextBox1.Clear()
    3. For Each line In IO.File.ReadAllLines("D:\1.txt") 'oder eben die passende Datei
    4. If line.StartsWith("1: ") Then TextBox1.Text = line.Replace("1: ", "")
    5. If line.StartsWith("2: ") Then TextBox1.Text = line.Replace("2: ", "")
    6. Next
    7. End Sub
    8. Private Sub SaveButton_Click(sender As System.Object, e As System.EventArgs) Handles SaveButton.Click
    9. Dim sw As New StreamWriter("D:\1.txt") 'siehe oben
    10. For lp_Index = 1 To TextBox1.Lines.Count
    11. sw.WriteLine(lp_Index & ": " & TextBox1.Lines(lp_Index - 1))
    12. Next
    13. sw.Close()
    14. End Sub


    Soviel dazu. Stellt sich die nächste Frage, was alles in die TextBox soll. Denn TextBox1.Text = line.Replace("1: ", "") überschreibt ja immer alles, was schon in der TextBox drin ist. Wenn das so sein soll, ok.
    Dieser Beitrag wurde bereits 5 mal editiert, zuletzt von „VaporiZed“, mal wieder aus Grammatikgründen.

    Aufgrund spontaner Selbsteintrübung sind all meine Glaskugeln beim Hersteller. Lasst mich daher bitte nicht den Spekulatiusbackmodus wechseln.
    @VaporiZed Die StreamWriter-Instanz packst Du bitte in einen Using-Block.
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    @Eierlein ich komme auf UTF-7, da dass so um Post erklärt wurde und diese Person das selbe Problem wie ich hatte. Sein Problem wurde aber nicht durch UTF-8 gelöst sondern durch UTF-7. also habe ich das genauso getan.

    @VaporiZed und @RodFromGermany vielen Dank für den Code. Ich werde ihn mir heute Nachmittag mal anschauen.
    Ich kam, sah und vergaß, was ich vorhatte.
    Also ich habe es mir jetzt nochmal angeschaut, alle Stellen, wo ich Encoding benutzt habe, erstmal entfernt, jedoch ändert das leider nichts an meinem Problem...
    Hier ist der Komplette Code:
    Spoiler anzeigen

    Quellcode

    1. ​Imports System.IO
    2. Public Class Form1
    3. #Region "Deklarationen"
    4. Dim dir As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments + "\Schulplaner"
    5. Dim plan_dir As String = dir + "\Plan"
    6. Dim fächer_dir As String = dir + "\Fächer"
    7. Dim mo_file As String = plan_dir + "\Montag.txt"
    8. Dim di_file As String = plan_dir + "\Dienstag.txt"
    9. Dim mi_file As String = plan_dir + "\Mittwoch.txt"
    10. Dim do_file As String = plan_dir + "\Donnerstag.txt"
    11. Dim fr_file As String = plan_dir + "\Freitag.txt"
    12. Dim lel As Integer = 0
    13. Dim dirs As ArrayList = New ArrayList()
    14. Dim files As ArrayList = New ArrayList()
    15. #End Region
    16. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    17. dirs.Add(dir)
    18. dirs.Add(plan_dir)
    19. dirs.Add(fächer_dir)
    20. files.Add(mo_file)
    21. files.Add(di_file)
    22. files.Add(mi_file)
    23. files.Add(do_file)
    24. files.Add(fr_file)
    25. For Each dir In dirs
    26. If Not (IO.Directory.Exists(dir)) Then
    27. Try
    28. IO.Directory.CreateDirectory(dir)
    29. Catch ex As Exception
    30. MessageBox.Show("Es ist ein unerwarteter Fehler aufgetreten. " + ex.Message, "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
    31. End Try
    32. End If
    33. Next
    34. End Sub
    35. Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles listDays.SelectedIndexChanged
    36. listSubs.Items.Clear()
    37. For Each file In IO.Directory.GetFiles(plan_dir)
    38. Dim name As String = file.Replace(plan_dir + "\", "")
    39. If (listDays.SelectedItem = name.Replace(".txt", "")) Then
    40. For Each line In IO.File.ReadAllLines(file)
    41. If line.StartsWith("1: ") Then
    42. listSubs.Items.Add(line.Replace("1: ", ""))
    43. ElseIf line.StartsWith("2: ") Then
    44. listSubs.Items.Add(line.Replace("2: ", ""))
    45. ElseIf line.StartsWith("3: ") Then
    46. listSubs.Items.Add(line.Replace("3: ", ""))
    47. ElseIf line.StartsWith("4: ") Then
    48. listSubs.Items.Add(line.Replace("4: ", ""))
    49. ElseIf line.StartsWith("5: ") Then
    50. listSubs.Items.Add(line.Replace("5: ", ""))
    51. ElseIf line.StartsWith("6: ") Then
    52. listSubs.Items.Add(line.Replace("6: ", ""))
    53. ElseIf line.StartsWith("7: ") Then
    54. listSubs.Items.Add(line.Replace("7: ", ""))
    55. ElseIf line.StartsWith("8: ") Then
    56. listSubs.Items.Add(line.Replace("8: ", ""))
    57. ElseIf line.StartsWith("9: ") Then
    58. listSubs.Items.Add(line.Replace("9: ", ""))
    59. End If
    60. Next
    61. Else
    62. End If
    63. Next
    64. End Sub
    65. Private Sub tabOptions_SelectedIndexChanged(sender As Object, e As EventArgs) Handles tabOptions.SelectedIndexChanged
    66. Dim selectedDay As String = plan_dir + "\" + tabStunden.SelectedIndex.ToString + ".txt"
    67. #Region "TabOptions"
    68. If (tabOptions.SelectedIndex.ToString = 0) Then
    69. Select Case tabStunden.SelectedIndex.ToString
    70. #Region "Montag"
    71. Case 0
    72. For Each line In IO.File.ReadAllLines(plan_dir + "\Montag.txt")
    73. If line.StartsWith("1: ") Then
    74. textSub1_mo.Text = line.Replace("1: ", "")
    75. ElseIf line.StartsWith("2: ") Then
    76. textSub2_mo.Text = line.Replace("2: ", "")
    77. ElseIf line.StartsWith("3: ") Then
    78. textSub3_mo.Text = line.Replace("3: ", "")
    79. ElseIf line.StartsWith("4: ") Then
    80. textSub4_mo.Text = line.Replace("4: ", "")
    81. ElseIf line.StartsWith("5: ") Then
    82. textSub5_mo.Text = line.Replace("5: ", "")
    83. ElseIf line.StartsWith("6: ") Then
    84. textSub6_mo.Text = line.Replace("6: ", "")
    85. ElseIf line.StartsWith("7: ") Then
    86. textSub7_mo.Text = line.Replace("7: ", "")
    87. ElseIf line.StartsWith("8: ") Then
    88. textSub8_mo.Text = line.Replace("8: ", "")
    89. ElseIf line.StartsWith("9: ") Then
    90. textSub9_mo.Text = line.Replace("9: ", "")
    91. End If
    92. Next
    93. #End Region
    94. #Region "Dienstag"
    95. Case 1
    96. For Each line In IO.File.ReadAllLines(plan_dir + "\Dienstag.txt")
    97. If line.StartsWith("1: ") Then
    98. textSub1_di.Text = line.Replace("1: ", "")
    99. ElseIf line.StartsWith("2: ") Then
    100. textSub2_di.Text = line.Replace("2: ", "")
    101. ElseIf line.StartsWith("3: ") Then
    102. textSub3_di.Text = line.Replace("3: ", "")
    103. ElseIf line.StartsWith("4: ") Then
    104. textSub4_di.Text = line.Replace("4: ", "")
    105. ElseIf line.StartsWith("5: ") Then
    106. textSub5_di.Text = line.Replace("5: ", "")
    107. ElseIf line.StartsWith("6: ") Then
    108. textSub6_di.Text = line.Replace("6: ", "")
    109. ElseIf line.StartsWith("7: ") Then
    110. textSub7_di.Text = line.Replace("7: ", "")
    111. ElseIf line.StartsWith("8: ") Then
    112. textSub8_di.Text = line.Replace("8: ", "")
    113. ElseIf line.StartsWith("9: ") Then
    114. textSub9_di.Text = line.Replace("9: ", "")
    115. End If
    116. Next
    117. #End Region
    118. #Region "Mittwoch"
    119. Case 2
    120. For Each line In IO.File.ReadAllLines(plan_dir + "\Mittwoch.txt")
    121. If line.StartsWith("1: ") Then
    122. textSub1_mi.Text = line.Replace("1: ", "")
    123. ElseIf line.StartsWith("2: ") Then
    124. textSub2_mi.Text = line.Replace("2: ", "")
    125. ElseIf line.StartsWith("3: ") Then
    126. textSub3_mi.Text = line.Replace("3: ", "")
    127. ElseIf line.StartsWith("4: ") Then
    128. textSub4_mi.Text = line.Replace("4: ", "")
    129. ElseIf line.StartsWith("5: ") Then
    130. textSub5_mi.Text = line.Replace("5: ", "")
    131. ElseIf line.StartsWith("6: ") Then
    132. textSub6_mi.Text = line.Replace("6: ", "")
    133. ElseIf line.StartsWith("7: ") Then
    134. textSub7_mi.Text = line.Replace("7: ", "")
    135. ElseIf line.StartsWith("8: ") Then
    136. textSub8_mi.Text = line.Replace("8: ", "")
    137. ElseIf line.StartsWith("9: ") Then
    138. textSub9_mi.Text = line.Replace("9: ", "")
    139. End If
    140. Next
    141. #End Region
    142. #Region "Donnerstag"
    143. Case 3
    144. For Each line In IO.File.ReadAllLines(plan_dir + "\Donnerstag.txt")
    145. If line.StartsWith("1: ") Then
    146. textSub1_do.Text = line.Replace("1: ", "")
    147. ElseIf line.StartsWith("2: ") Then
    148. textSub2_do.Text = line.Replace("2: ", "")
    149. ElseIf line.StartsWith("3: ") Then
    150. textSub3_do.Text = line.Replace("3: ", "")
    151. ElseIf line.StartsWith("4: ") Then
    152. textSub4_do.Text = line.Replace("4: ", "")
    153. ElseIf line.StartsWith("5: ") Then
    154. textSub5_do.Text = line.Replace("5: ", "")
    155. ElseIf line.StartsWith("6: ") Then
    156. textSub6_do.Text = line.Replace("6: ", "")
    157. ElseIf line.StartsWith("7: ") Then
    158. textSub7_do.Text = line.Replace("7: ", "")
    159. ElseIf line.StartsWith("8: ") Then
    160. textSub8_do.Text = line.Replace("8: ", "")
    161. ElseIf line.StartsWith("9: ") Then
    162. textSub9_do.Text = line.Replace("9: ", "")
    163. End If
    164. Next
    165. #End Region
    166. #Region "Freitag"
    167. Case 4
    168. For Each line In IO.File.ReadAllLines(plan_dir + "\Freitag.txt")
    169. If line.StartsWith("1: ") Then
    170. textSub1_fr.Text = line.Replace("1: ", "")
    171. ElseIf line.StartsWith("2: ") Then
    172. textSub2_fr.Text = line.Replace("2: ", "")
    173. ElseIf line.StartsWith("3: ") Then
    174. textSub3_fr.Text = line.Replace("3: ", "")
    175. ElseIf line.StartsWith("4: ") Then
    176. textSub4_fr.Text = line.Replace("4: ", "")
    177. ElseIf line.StartsWith("5: ") Then
    178. textSub5_fr.Text = line.Replace("5: ", "")
    179. ElseIf line.StartsWith("6: ") Then
    180. textSub6_fr.Text = line.Replace("6: ", "")
    181. ElseIf line.StartsWith("7: ") Then
    182. textSub7_fr.Text = line.Replace("7: ", "")
    183. ElseIf line.StartsWith("8: ") Then
    184. textSub8_fr.Text = line.Replace("8: ", "")
    185. ElseIf line.StartsWith("9: ") Then
    186. textSub9_fr.Text = line.Replace("9: ", "")
    187. End If
    188. Next
    189. #End Region
    190. End Select
    191. End If
    192. #End Region
    193. End Sub
    194. Private Sub tabMain_SelectedIndexChanged(sender As Object, e As EventArgs) Handles tabMain.SelectedIndexChanged
    195. If (tabMain.SelectedIndex.ToString = 1 And tabOptions.SelectedIndex.ToString = 0) Then
    196. Select Case tabStunden.SelectedIndex.ToString
    197. #Region "Montag"
    198. Case 0
    199. For Each line In IO.File.ReadAllLines(plan_dir + "\Montag.txt")
    200. If line.StartsWith("1: ") Then
    201. textSub1_mo.Text = line.Replace("1: ", "")
    202. ElseIf line.StartsWith("2: ") Then
    203. textSub2_mo.Text = line.Replace("2: ", "")
    204. ElseIf line.StartsWith("3: ") Then
    205. textSub3_mo.Text = line.Replace("3: ", "")
    206. ElseIf line.StartsWith("4: ") Then
    207. textSub4_mo.Text = line.Replace("4: ", "")
    208. ElseIf line.StartsWith("5: ") Then
    209. textSub5_mo.Text = line.Replace("5: ", "")
    210. ElseIf line.StartsWith("6: ") Then
    211. textSub6_mo.Text = line.Replace("6: ", "")
    212. ElseIf line.StartsWith("7: ") Then
    213. textSub7_mo.Text = line.Replace("7: ", "")
    214. ElseIf line.StartsWith("8: ") Then
    215. textSub8_mo.Text = line.Replace("8: ", "")
    216. ElseIf line.StartsWith("9: ") Then
    217. textSub9_mo.Text = line.Replace("9: ", "")
    218. End If
    219. Next
    220. #End Region
    221. #Region "Dienstag"
    222. Case 1
    223. For Each line In IO.File.ReadAllLines(plan_dir + "\Dienstag.txt")
    224. If line.StartsWith("1: ") Then
    225. textSub1_di.Text = line.Replace("1: ", "")
    226. ElseIf line.StartsWith("2: ") Then
    227. textSub2_di.Text = line.Replace("2: ", "")
    228. ElseIf line.StartsWith("3: ") Then
    229. textSub3_di.Text = line.Replace("3: ", "")
    230. ElseIf line.StartsWith("4: ") Then
    231. textSub4_di.Text = line.Replace("4: ", "")
    232. ElseIf line.StartsWith("5: ") Then
    233. textSub5_di.Text = line.Replace("5: ", "")
    234. ElseIf line.StartsWith("6: ") Then
    235. textSub6_di.Text = line.Replace("6: ", "")
    236. ElseIf line.StartsWith("7: ") Then
    237. textSub7_di.Text = line.Replace("7: ", "")
    238. ElseIf line.StartsWith("8: ") Then
    239. textSub8_di.Text = line.Replace("8: ", "")
    240. ElseIf line.StartsWith("9: ") Then
    241. textSub9_di.Text = line.Replace("9: ", "")
    242. End If
    243. Next
    244. #End Region
    245. #Region "Mittwoch"
    246. Case 2
    247. For Each line In IO.File.ReadAllLines(plan_dir + "\Mittwoch.txt")
    248. If line.StartsWith("1: ") Then
    249. textSub1_mi.Text = line.Replace("1: ", "")
    250. ElseIf line.StartsWith("2: ") Then
    251. textSub2_mi.Text = line.Replace("2: ", "")
    252. ElseIf line.StartsWith("3: ") Then
    253. textSub3_mi.Text = line.Replace("3: ", "")
    254. ElseIf line.StartsWith("4: ") Then
    255. textSub4_mi.Text = line.Replace("4: ", "")
    256. ElseIf line.StartsWith("5: ") Then
    257. textSub5_mi.Text = line.Replace("5: ", "")
    258. ElseIf line.StartsWith("6: ") Then
    259. textSub6_mi.Text = line.Replace("6: ", "")
    260. ElseIf line.StartsWith("7: ") Then
    261. textSub7_mi.Text = line.Replace("7: ", "")
    262. ElseIf line.StartsWith("8: ") Then
    263. textSub8_mi.Text = line.Replace("8: ", "")
    264. ElseIf line.StartsWith("9: ") Then
    265. textSub9_mi.Text = line.Replace("9: ", "")
    266. End If
    267. Next
    268. #End Region
    269. #Region "Donnerstag"
    270. Case 3
    271. For Each line In IO.File.ReadAllLines(plan_dir + "\Donnerstag.txt")
    272. If line.StartsWith("1: ") Then
    273. textSub1_do.Text = line.Replace("1: ", "")
    274. ElseIf line.StartsWith("2: ") Then
    275. textSub2_do.Text = line.Replace("2: ", "")
    276. ElseIf line.StartsWith("3: ") Then
    277. textSub3_do.Text = line.Replace("3: ", "")
    278. ElseIf line.StartsWith("4: ") Then
    279. textSub4_do.Text = line.Replace("4: ", "")
    280. ElseIf line.StartsWith("5: ") Then
    281. textSub5_do.Text = line.Replace("5: ", "")
    282. ElseIf line.StartsWith("6: ") Then
    283. textSub6_do.Text = line.Replace("6: ", "")
    284. ElseIf line.StartsWith("7: ") Then
    285. textSub7_do.Text = line.Replace("7: ", "")
    286. ElseIf line.StartsWith("8: ") Then
    287. textSub8_do.Text = line.Replace("8: ", "")
    288. ElseIf line.StartsWith("9: ") Then
    289. textSub9_do.Text = line.Replace("9: ", "")
    290. End If
    291. Next
    292. #End Region
    293. #Region "Freitag"
    294. Case 4
    295. For Each line In IO.File.ReadAllLines(plan_dir + "\Freitag.txt")
    296. If line.StartsWith("1: ") Then
    297. textSub1_fr.Text = line.Replace("1: ", "")
    298. ElseIf line.StartsWith("2: ") Then
    299. textSub2_fr.Text = line.Replace("2: ", "")
    300. ElseIf line.StartsWith("3: ") Then
    301. textSub3_fr.Text = line.Replace("3: ", "")
    302. ElseIf line.StartsWith("4: ") Then
    303. textSub4_fr.Text = line.Replace("4: ", "")
    304. ElseIf line.StartsWith("5: ") Then
    305. textSub5_fr.Text = line.Replace("5: ", "")
    306. ElseIf line.StartsWith("6: ") Then
    307. textSub6_fr.Text = line.Replace("6: ", "")
    308. ElseIf line.StartsWith("7: ") Then
    309. textSub7_fr.Text = line.Replace("7: ", "")
    310. ElseIf line.StartsWith("8: ") Then
    311. textSub8_fr.Text = line.Replace("8: ", "")
    312. ElseIf line.StartsWith("9: ") Then
    313. textSub9_fr.Text = line.Replace("9: ", "")
    314. End If
    315. Next
    316. #End Region
    317. End Select
    318. End If
    319. End Sub
    320. Private Sub tabStunden_SelectedIndexChanged(sender As Object, e As EventArgs) Handles tabStunden.SelectedIndexChanged
    321. Select Case tabStunden.SelectedIndex.ToString
    322. #Region "Montag"
    323. Case 0
    324. For Each line In IO.File.ReadAllLines(plan_dir + "\Montag.txt")
    325. If line.StartsWith("1: ") Then
    326. textSub1_mo.Text = line.Replace("1: ", "")
    327. ElseIf line.StartsWith("2: ") Then
    328. textSub2_mo.Text = line.Replace("2: ", "")
    329. ElseIf line.StartsWith("3: ") Then
    330. textSub3_mo.Text = line.Replace("3: ", "")
    331. ElseIf line.StartsWith("4: ") Then
    332. textSub4_mo.Text = line.Replace("4: ", "")
    333. ElseIf line.StartsWith("5: ") Then
    334. textSub5_mo.Text = line.Replace("5: ", "")
    335. ElseIf line.StartsWith("6: ") Then
    336. textSub6_mo.Text = line.Replace("6: ", "")
    337. ElseIf line.StartsWith("7: ") Then
    338. textSub7_mo.Text = line.Replace("7: ", "")
    339. ElseIf line.StartsWith("8: ") Then
    340. textSub8_mo.Text = line.Replace("8: ", "")
    341. ElseIf line.StartsWith("9: ") Then
    342. textSub9_mo.Text = line.Replace("9: ", "")
    343. End If
    344. Next
    345. #End Region
    346. #Region "Dienstag"
    347. Case 1
    348. For Each line In IO.File.ReadAllLines(plan_dir + "\Dienstag.txt")
    349. If line.StartsWith("1: ") Then
    350. textSub1_di.Text = line.Replace("1: ", "")
    351. ElseIf line.StartsWith("2: ") Then
    352. textSub2_di.Text = line.Replace("2: ", "")
    353. ElseIf line.StartsWith("3: ") Then
    354. textSub3_di.Text = line.Replace("3: ", "")
    355. ElseIf line.StartsWith("4: ") Then
    356. textSub4_di.Text = line.Replace("4: ", "")
    357. ElseIf line.StartsWith("5: ") Then
    358. textSub5_di.Text = line.Replace("5: ", "")
    359. ElseIf line.StartsWith("6: ") Then
    360. textSub6_di.Text = line.Replace("6: ", "")
    361. ElseIf line.StartsWith("7: ") Then
    362. textSub7_di.Text = line.Replace("7: ", "")
    363. ElseIf line.StartsWith("8: ") Then
    364. textSub8_di.Text = line.Replace("8: ", "")
    365. ElseIf line.StartsWith("9: ") Then
    366. textSub9_di.Text = line.Replace("9: ", "")
    367. End If
    368. Next
    369. #End Region
    370. #Region "Mittwoch"
    371. Case 2
    372. For Each line In IO.File.ReadAllLines(plan_dir + "\Mittwoch.txt")
    373. If line.StartsWith("1: ") Then
    374. textSub1_mi.Text = line.Replace("1: ", "")
    375. ElseIf line.StartsWith("2: ") Then
    376. textSub2_mi.Text = line.Replace("2: ", "")
    377. ElseIf line.StartsWith("3: ") Then
    378. textSub3_mi.Text = line.Replace("3: ", "")
    379. ElseIf line.StartsWith("4: ") Then
    380. textSub4_mi.Text = line.Replace("4: ", "")
    381. ElseIf line.StartsWith("5: ") Then
    382. textSub5_mi.Text = line.Replace("5: ", "")
    383. ElseIf line.StartsWith("6: ") Then
    384. textSub6_mi.Text = line.Replace("6: ", "")
    385. ElseIf line.StartsWith("7: ") Then
    386. textSub7_mi.Text = line.Replace("7: ", "")
    387. ElseIf line.StartsWith("8: ") Then
    388. textSub8_mi.Text = line.Replace("8: ", "")
    389. ElseIf line.StartsWith("9: ") Then
    390. textSub9_mi.Text = line.Replace("9: ", "")
    391. End If
    392. Next
    393. #End Region
    394. #Region "Donnerstag"
    395. Case 3
    396. For Each line In IO.File.ReadAllLines(plan_dir + "\Donnerstag.txt")
    397. If line.StartsWith("1: ") Then
    398. textSub1_do.Text = line.Replace("1: ", "")
    399. ElseIf line.StartsWith("2: ") Then
    400. textSub2_do.Text = line.Replace("2: ", "")
    401. ElseIf line.StartsWith("3: ") Then
    402. textSub3_do.Text = line.Replace("3: ", "")
    403. ElseIf line.StartsWith("4: ") Then
    404. textSub4_do.Text = line.Replace("4: ", "")
    405. ElseIf line.StartsWith("5: ") Then
    406. textSub5_do.Text = line.Replace("5: ", "")
    407. ElseIf line.StartsWith("6: ") Then
    408. textSub6_do.Text = line.Replace("6: ", "")
    409. ElseIf line.StartsWith("7: ") Then
    410. textSub7_do.Text = line.Replace("7: ", "")
    411. ElseIf line.StartsWith("8: ") Then
    412. textSub8_do.Text = line.Replace("8: ", "")
    413. ElseIf line.StartsWith("9: ") Then
    414. textSub9_do.Text = line.Replace("9: ", "")
    415. End If
    416. Next
    417. #End Region
    418. #Region "Freitag"
    419. Case 4
    420. For Each line In IO.File.ReadAllLines(plan_dir + "\Freitag.txt")
    421. If line.StartsWith("1: ") Then
    422. textSub1_fr.Text = line.Replace("1: ", "")
    423. ElseIf line.StartsWith("2: ") Then
    424. textSub2_fr.Text = line.Replace("2: ", "")
    425. ElseIf line.StartsWith("3: ") Then
    426. textSub3_fr.Text = line.Replace("3: ", "")
    427. ElseIf line.StartsWith("4: ") Then
    428. textSub4_fr.Text = line.Replace("4: ", "")
    429. ElseIf line.StartsWith("5: ") Then
    430. textSub5_fr.Text = line.Replace("5: ", "")
    431. ElseIf line.StartsWith("6: ") Then
    432. textSub6_fr.Text = line.Replace("6: ", "")
    433. ElseIf line.StartsWith("7: ") Then
    434. textSub7_fr.Text = line.Replace("7: ", "")
    435. ElseIf line.StartsWith("8: ") Then
    436. textSub8_fr.Text = line.Replace("8: ", "")
    437. ElseIf line.StartsWith("9: ") Then
    438. textSub9_fr.Text = line.Replace("9: ", "")
    439. End If
    440. Next
    441. #End Region
    442. End Select
    443. End Sub
    444. Private Sub btnSpeichern_Click(sender As Object, e As EventArgs) Handles btnSpeichern.Click
    445. Select Case tabOptions.SelectedIndex.ToString
    446. Case 0
    447. Dim selectedDay As String = tabStunden.SelectedIndex.ToString
    448. Select Case selectedDay
    449. #Region "Montag"
    450. Case 0
    451. Using sw As StreamWriter = New StreamWriter(mo_file)
    452. sw.Write("")
    453. sw.WriteLine("1: " + textSub1_mo.Text)
    454. sw.WriteLine("2: " + textSub2_mo.Text)
    455. sw.WriteLine("3: " + textSub3_mo.Text)
    456. sw.WriteLine("4: " + textSub4_mo.Text)
    457. sw.WriteLine("5: " + textSub5_mo.Text)
    458. sw.WriteLine("6: " + textSub6_mo.Text)
    459. sw.WriteLine("7: " + textSub7_mo.Text)
    460. sw.WriteLine("8: " + textSub8_mo.Text)
    461. sw.WriteLine("9: " + textSub9_mo.Text)
    462. sw.Close()
    463. sw.Dispose()
    464. MsgBox("Klappt")
    465. End Using
    466. #End Region
    467. #Region "Dienstag"
    468. Case 1
    469. MsgBox("Dienstag")
    470. #End Region
    471. #Region "Mittwoch"
    472. Case 2
    473. MsgBox("Mittwoch")
    474. #End Region
    475. #Region "Donnerstag"
    476. Case 3
    477. MsgBox("Donnerstag")
    478. #End Region
    479. #Region "Freitag"
    480. Case 4
    481. MsgBox("Freitag")
    482. #End Region
    483. End Select
    484. Case 1
    485. End Select
    486. End Sub
    487. End Class

    Fällt euch etwas auf, was das Problem sein könnte? @RodFromGermany @VaporiZed
    Ich habe hier nochmal ein Bild von dem Problem.
    Ich kam, sah und vergaß, was ich vorhatte.
    @Cozy Verwende mal bei ReadAllLines() ebenfalls dieses Encoding als 2. Parameter.
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    @RodFromGermany vielen dank! Habe es jetzt mit UTF8 probiert, da es mit UTF7 immer noch nicht geklappt hatte. Tut mir leid @Eierlein
    Habe jetzt fürs schreiben:

    VB.NET-Quellcode

    1. sw.WriteLine("1: " + textSub1_mo.Text, System.Text.Encoding.UTF8)​

    Und fürs auslesen:

    VB.NET-Quellcode

    1. IO.File.ReadAllLines(file, System.Text.Encoding.UTF8)​
    Ich kam, sah und vergaß, was ich vorhatte.