Implementation of string wrapping in IOS

Time:2019-10-31

Preface

Today, I came across a requirement that a string of strings returned from the background is @ “1, Hello, how are you in the new year; 2, how are you in the new year; 3, how are you in the new year.” this is how you put it in the sealed alert prompt box.

The requirement of optimization is to display the new line in the format of the alert box.

Resolvent

Just now, the idea is string splicing @ “\ n”. I took a detour at the beginning, because it is to encapsulate the alert, so I went to process the string in the alert when the string passed an alert. Later, I found that I couldn’t do it. When I spliced the @ “\ n”, nslog printed it out as a new line, but it was put back on the alert as it was before. Later, I found that I manually gave it to you. String can be divided by adding @ “\ n” to the string @ “Hello \ n hello”. When I was just writing and printing, the line was divided, but the string was not spliced to @ “\ n”, so alert is still the same as before. So later, I want to process this string from the beginning, take it directly to the string returned in the background, and then directly splice it. Common spelling If it doesn’t work, it’s still the same, @ “\ \ n”, \ n is spliced, but it doesn’t break the line, that is, simple characters are spliced into strings.

Later, I added a sentence that means replace, and then it will be OK.

Finally, I optimized the for loop array to delete directly. Finally, I added a judgment, if the background returned Chinese “;” or English “;” or no time.

A rookie, originally quite a simple optimization, and finally what about Baidu? It took me half an hour to figure it out.

summary

The above is the whole content of this article. I hope that the content of this article has a certain reference learning value for everyone’s study or work. If you have any questions, you can leave a message and exchange. Thank you for your support for developepaar.

Recommended Today

Using VBS to realize the function of browsing folder in Windows Script Host

‘************************************************ ‘ File:Dialog.vbs (WSH sample in VBScript)  ‘ Author:(c) G. Born ‘ ‘ Using the shell dialog box to select a folder ‘************************************************ Option Explicit ‘ Flags for the options parameter Const BIF_returnonlyfsdirs = &H0001 Const BIF_dontgobelowdomain= &H0002 Const BIF_statustext = &H0004 Const BIF_returnfsancestors= &H0008 Const BIF_editbox= &H0010 Const BIF_validate = &H0020 Const BIF_browseforcomputer= &H1000 Const BIF_browseforprinter = &H2000 Const BIF_browseincludefiles = &H4000 Dim wsh, objDlg, objF ‘ Get Application object of the Windows shell. Set objDlg = WScript.CreateObject(“Shell.Application”) ‘ Use the BrowseForFolder method. ‘ For instance: Set objF = objDlg.BrowseForFolder _ ‘ (&H0, “Select the folder to copy”, &H10, “C:\Born”) Set objF = objDlg.BrowseForFolder (&H0, _ “Select the folder to copy”, _ BIF_editbox + BIF_returnonlyfsdirs) ‘ Here we use the first method to detect the result. If IsValue(objF) Then  MsgBox “Selected folder: ” & objF.Title Else MsgBox “Canceled” End If ‘ Here we use TypeName to detect the result. If InStr(1, TypeName(objF), “Folder”) > 0 Then MsgBox “Selected folder: ” & objF.Title Else MsgBox “Canceled” End If Function IsValue(obj) ‘ Check whether the value has been returned. Dim tmp On Error Resume Next tmp = ” ” & obj If Err <> 0 Then IsValue = False Else IsValue = True End If On Error GoTo 0 End Function ‘*** End