C camolas Member Licensed User Longtime User Feb 26, 2015 #1 Hi, Please i need hellp on modify a existing txt but i only want to change one line. example: Code: 1 2 3 4 or 1,2,3,4 I want to replace the third position to A and leave the others without any change Code: 1 2 A 4 or 1,2,A,4 Its is possible? Thanks
Hi, Please i need hellp on modify a existing txt but i only want to change one line. example: Code: 1 2 3 4 or 1,2,3,4 I want to replace the third position to A and leave the others without any change Code: 1 2 A 4 or 1,2,A,4 Its is possible? Thanks
KMatle Expert Licensed User Longtime User Feb 26, 2015 #2 MyText=Mytext.Replace("3", "A") Take a look at string functions of B4A Upvote 0
stevel05 Expert Licensed User Longtime User Feb 26, 2015 #3 If you don't know the value of the 3rd entry, you can use Regex.Split: Code: Sub FieldReplace(FieldNo As Int,Delim As String,Source As String,ReplacementStr As String) As String 'Stops arrayindex out of bounds error If FieldNo < 0 Then Return Source Dim T() As String = Regex.Split(Delim,Source) 'Stops arrayindex out of bounds error If FieldNo >= T.Length Then Return Source T(FieldNo) = ReplacementStr 'Build Return String Dim ReturnStr As String For i = 0 To T.Length - 1 ReturnStr = ReturnStr & T(i) If i < T.Length - 1 Then ReturnStr = ReturnStr & Delim Next Return ReturnStr End Sub Use As: Code: Dim Str As String = "1,2,3,4" Log(FieldReplace(2,",",Str,"A")) 'Positions are zero based same as arrays Last edited: Feb 26, 2015 Upvote 0
If you don't know the value of the 3rd entry, you can use Regex.Split: Code: Sub FieldReplace(FieldNo As Int,Delim As String,Source As String,ReplacementStr As String) As String 'Stops arrayindex out of bounds error If FieldNo < 0 Then Return Source Dim T() As String = Regex.Split(Delim,Source) 'Stops arrayindex out of bounds error If FieldNo >= T.Length Then Return Source T(FieldNo) = ReplacementStr 'Build Return String Dim ReturnStr As String For i = 0 To T.Length - 1 ReturnStr = ReturnStr & T(i) If i < T.Length - 1 Then ReturnStr = ReturnStr & Delim Next Return ReturnStr End Sub Use As: Code: Dim Str As String = "1,2,3,4" Log(FieldReplace(2,",",Str,"A")) 'Positions are zero based same as arrays
C camolas Member Licensed User Longtime User Feb 26, 2015 #4 Ok, now how can i save the replace "field" to txt (only the modify and keep the others)? Special thanks to @KMatle and @stevel05 Upvote 0
Ok, now how can i save the replace "field" to txt (only the modify and keep the others)? Special thanks to @KMatle and @stevel05
stevel05 Expert Licensed User Longtime User Feb 26, 2015 #5 Code: Sub GetField(FieldNo As Int,Delim As String,Source As String) As String 'Stops arrayindex out of bounds error If FieldNo < 0 Then Return "" Dim T() As String = Regex.Split(Delim,Source) 'Stops arrayindex out of bounds error If FieldNo >= T.Length Then Return "" Return T(FieldNo) End Sub Usage: Code: Dim Str As String = "1,2,3,4" Dim TexttoReplace As String = GetField(2,",",Str) Log(FieldReplace(2,",",Str,"A")) Upvote 0
Code: Sub GetField(FieldNo As Int,Delim As String,Source As String) As String 'Stops arrayindex out of bounds error If FieldNo < 0 Then Return "" Dim T() As String = Regex.Split(Delim,Source) 'Stops arrayindex out of bounds error If FieldNo >= T.Length Then Return "" Return T(FieldNo) End Sub Usage: Code: Dim Str As String = "1,2,3,4" Dim TexttoReplace As String = GetField(2,",",Str) Log(FieldReplace(2,",",Str,"A"))
C camolas Member Licensed User Longtime User Feb 27, 2015 #6 This write the update txt to device? Upvote 0
stevel05 Expert Licensed User Longtime User Feb 27, 2015 #7 No, it will be in the variable TexttoReplace. you can use TextWriter: https://www.b4x.com/android/help/files.html#textwriter to save it to a file. Upvote 0
No, it will be in the variable TexttoReplace. you can use TextWriter: https://www.b4x.com/android/help/files.html#textwriter to save it to a file.
DonManfred Expert Licensed User Longtime User Feb 27, 2015 #8 I suggest starting at the Beginners Guide and then working trhrough it and all it´s samples to get further. The start at the users guide (all examples here too) then. It should dont need this thread knowing the basics! Upvote 0
I suggest starting at the Beginners Guide and then working trhrough it and all it´s samples to get further. The start at the users guide (all examples here too) then. It should dont need this thread knowing the basics!
Cableguy Expert Licensed User Longtime User Feb 27, 2015 #9 DonManfred said: It should dont need this thread knowing the basics! Click to expand... exactly! Upvote 0
C camolas Member Licensed User Longtime User Feb 27, 2015 #10 Code: Sub bt_1_Click Dim xx As String xx = 1 Stre = Items(0) & "," & Items(1) & "," & xx & "," & Items(3) File.WriteString(File.DirRootExternal, "TT.txt", _ Stre) End Sub Thanks @stevel05 @Manfred i dont now why every time you reply to my posts you have to implicate... Code: https://www.b4x.com/android/forum/threads/solved-tts-service-for-2-activitys.49877/#post-311439 Upvote 0
Code: Sub bt_1_Click Dim xx As String xx = 1 Stre = Items(0) & "," & Items(1) & "," & xx & "," & Items(3) File.WriteString(File.DirRootExternal, "TT.txt", _ Stre) End Sub Thanks @stevel05 @Manfred i dont now why every time you reply to my posts you have to implicate... Code: https://www.b4x.com/android/forum/threads/solved-tts-service-for-2-activitys.49877/#post-311439
Cableguy Expert Licensed User Longtime User Feb 27, 2015 #11 camolas said: Code: Sub bt_1_Click Dim xx As String xx = 1 Stre = Items(0) & "," & Items(1) & "," & xx & "," & Items(3) File.WriteString(File.DirRootExternal, "TT.txt", _ Stre) End Sub Thanks @stevel05 @Manfred i dont now why every time you reply to my posts you have to implicate... Code: https://www.b4x.com/android/forum/threads/solved-tts-service-for-2-activitys.49877/#post-311439 Click to expand... He is not implicating... but there are noob questions... and then there are the "I don't care about the search engine on the top right of the this site" questions... yours are more on the later category... Upvote 0
camolas said: Code: Sub bt_1_Click Dim xx As String xx = 1 Stre = Items(0) & "," & Items(1) & "," & xx & "," & Items(3) File.WriteString(File.DirRootExternal, "TT.txt", _ Stre) End Sub Thanks @stevel05 @Manfred i dont now why every time you reply to my posts you have to implicate... Code: https://www.b4x.com/android/forum/threads/solved-tts-service-for-2-activitys.49877/#post-311439 Click to expand... He is not implicating... but there are noob questions... and then there are the "I don't care about the search engine on the top right of the this site" questions... yours are more on the later category...
C camolas Member Licensed User Longtime User Feb 27, 2015 #12 I dont wont to start any problems i just fell what i write just that... Thanks Upvote 0