How to insert Date/Time at cursor position multiline EditText?

rwblinn

Well-Known Member
Licensed User
Longtime User
Dear All,

how to insert Date/Time at cursor position multiline EditText?

Appreciated,
Robert
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use this method to insert strings inside a string:
B4X:
Sub Insert(original As String, ins As String, index As Int) As String
   Dim pre, suf As String
   If index > 0 Then pre = original.SubString2(0, index)
   If index < original.Length Then suf = original.SubString(index)
   Return pre & ins & suf
End Sub

Your code:
B4X:
Dim str As String = DateUtils.TicksToString(DateTime.Now)
et.Text = Insert(et.Text,str , et.SelectionStart)
et.SelectionStart = et.SelectionStart + str.Length
 
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
Insert DateTime @cursor position in EditText

Erel,

works perfect.

Many thanks for this solution.

Rob
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…