试图写小写的文件名 [英] trying to write file name in lower case
本文介绍了试图写小写的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有代码从文本框中获取姓氏的名字和名字的首字母缩写,并在写入文件时将其用作文件名,但是我输入的使文件名全部小写的代码不起作用
I have the code to take the first name and first initial of last name from a text box and use it as a file name when writing to file, but the code I input to make the file name all lower case is not working
Private Sub ButtonWrite_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonWrite.Click
If TextBoxCusName.Text = String.Empty Then
MessageBox.Show("Please enter a Customer name before writing to file")
Else
'Create file stream object to access the file system
Dim MyFileStream As FileStream
Dim FilePath As String = Application.StartupPath
Dim FileDynamicPath As String = "" 'FilePath & "\test.txt"
'Create FileName
Dim iPosition As Integer = 0
Dim strName As String = Me.TextBoxCusName.Text
Dim strTitle As String = Me.CheckedListBoxCusTitle.Text
'Finding position of first space
iPosition = InStr(strName, " ", CompareMethod.Text)
'Finding First Name and the first letter of the last name
Dim FirstName As String
Dim FirstLetterofLastName As String = ""
FirstName = Microsoft.VisualBasic.Left(strName, iPosition - 1)
FirstLetterofLastName = Microsoft.VisualBasic.Mid(strName, iPosition + 1, 1)
'Create FileName
FileDynamicPath = FirstName & FirstLetterofLastName & ".txt"
MyFileStream = New FileStream(FileDynamicPath, FileMode.OpenOrCreate, FileAccess.Write)
'Stream Writer
Dim myStreamWriter As StreamWriter
myStreamWriter = New StreamWriter(MyFileStream)
'Write to the file
myStreamWriter.WriteLine(strName.ToLower & vbCrLf + strTitle) 'the lower case does not work, cannot figure out why or where it should go to work
MessageBox.Show("File has been written")
'still need to write the code to check to see if file exists and if it should be overwritten
myStreamWriter.Close()
End If
End Sub
推荐答案
那是因为您不能直接使用它.
如果您先用它分配一个变量,它将起作用.
That''s because you can''t use it directly.
If you''ll first assign a variable with it, it''ll work.
Dim strNameL as string = strName.ToLower
myStreamWriter.WriteLine(strNameL & vbCrLf + strTitle)
thatraja,即使没有括号也可以编译代码...文件名只是没有转换为小写
Scubapro,谢谢您的帮助...我实际上只是修改了定义名字和姓氏的代码的代码,它起作用了
thatraja, the code compiled even without the parenthesis...the file name just did not convert to lower case
Scubapro, thanks for your help...I actually just modified the code defining the first name and the first letter of the last name and it worked
FirstName = Microsoft.VisualBasic.Left(strName.ToLower, iPosition - 1)
FirstLetterofLastName = Microsoft.VisualBasic.Mid(strName.ToLower, iPosition + 1, 1)
myStreamWriter.WriteLine(New String(strName.ToLower) & vbCrLf + strTitle)
这篇关于试图写小写的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文