Android Question Change a word in the text

Mahares

Expert
Licensed User
Longtime User
need cod for when I click button change a word in the text.
Something like this:
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private s As String
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")  'has button1
    s= File.ReadString(File.DirAssets, "darkwolf.txt") 'suppose you have a text file in assets folder
End Sub

Private Sub Button1_Click
    s=s.Replace("DarkWolfalpha", "LightWolfbeta") 'you want to replace DarkWolfalpha with LightWolfbeta
    File.WriteString(File.DirInternal,  "lightwolf.txt", s) 'you cannot save it back to assets folder.because assets is read only    
    Log(File.ReadString(File.DirInternal, "lightwolf.txt"))  'shows you the new file with the changes
End Sub
 
Upvote 0
Top