Success.i = CkStringBuilder:: ckDecodeAndAppend(sb1,nameWindows1252UrlEncoded, "url", "windows-1252") In the above example, we have the same string, but in different charset encodings subsequently URL encoded. NameUtf8UrlEncoded.s = "M%C3%86RSK" Note that the result of loading a string into a string object is the same if we correctly specify the underlying charset encoding. NameWindows1252UrlEncoded.s = "M%C6RSK" This is the URL encoding of the utf-8 representation. We have the string "MÆRSK" in two forms: This is the URL encoding of the windows-1252 representation. Note: This example uses the new DecodeAndAppend method added in Chilkat v9.5.0.87. Procedure FindStringIndexChris(String.s, StringFind.s, Index.i)ĭefine String.(PureBasic) Decode from Binary Encoding and Append Stringĭemonstrates how to decode from a binary encoding (base64, hex, url, etc.) and then append the decoded string to a Chilkat StringBuilder object. Position = FindString(string, StringFind, Position) If Index > 0 And Not String = "" And Not StringFind = "" Procedure FindStringIndexLord(string.s, StringFind.s, Index.i) *String + LenStringFind * SizeOf(character)ĭebug "FindStringIndex(" + String + ", " + StringFind + ", 2) = " + FindStringIndex(String, StringFind, 2)ĭebug "FindStringIndex(" + String + ", " + StringFind + ", 0) = " + FindStringIndex(String, StringFind, 0)ĭebug "FindStringIndex(" + String + ", " + StringFind + ", 1) = " + FindStringIndex(String, StringFind, 1)ĭebug "FindStringIndex(" + String + ", " + StringFind + ", 3) = " + FindStringIndex(String, StringFind, 3)ĭebug "FindStringIndex(" + String + ", " + StringFind + ", 4) = " + FindStringIndex(String, StringFind, 4) If Index = LenStringFind And CompareMemoryString(*String, *StringFind, #PB_String_CaseSensitive, LenStringFind) = #PB_String_Equal) Protected LenStringFind.i, Find.i, FindIndex.i, Position.i, Exit.i Protected *String.character, *StringFind.character Procedure FindStringIndex(String.s, StringFind.s, Index.i) String.s = "words/are/separated/by/bracketed/delimiters/like/this."ĭebug Find_String_Index(string.s, "/", 2) <- Will return 10ĭebug Find_String_Index(string.s, "/", 5) <- Will return 33ĭebug Find_String_Index(string.s, "/", 7) <- Will return 49ĭebug Find_String_Index(string.s, "/", 8) <- Will return 0 since there are only 7 sub-stringsĭebug Find_String_Index(string.s, "/", 0) <- Test nonsense value, will return 0 ProcedureReturn foundpos.q Return character position where this count foundĭefine string.s = "words()are()separated()by()bracketed()delimiters()like()this."ĭebug Find_String_Index(string.s, "()", 2) <- Will return 11ĭebug Find_String_Index(string.s, "()", 5) <- Will return 37ĭebug Find_String_Index(string.s, "()", 7) <- Will return 55ĭebug Find_String_Index(string.s, "()", 8) <- Will return 0 since there are only 7 sub-stringsĭebug Find_String_Index(string.s, "()", 0) <- Test nonsense value, will return 0 Stpos.q = findpos.q + 1 Set next start position one char on from found pos.įoundpos.q = findpos.q Set the position of the final 'index' occurrenceĭone.b = #True FindString() didn't find, so nothing more to do If findpos.q Found sub-string with position findpos.qįindcnt.q + 1 Increment our occurrence counter While Not(done.b) Loop until exit flag setįindpos.q = FindString(string.s, find.s, stpos.q) Find sub-string with rolling start position stpos Stpos.q = 1 Start at position 1 of string to be searched If index.q > 0 Index.q value must be at least 1 Procedure.q Find_String_Index(string.s, find.s, index.q)ĭefine findpos.q Running FindString() result for each occurrenceĭefine foundpos.q Found position of n-th occurrenceĭefine findcnt.q Running counter of found sub-stringĭefine stpos.q Running start position for FindString() ** Find position of n-th occurrence of a sub-string in a string - for example the 3rd "/" in 1/2/3/4/5 would be 6
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |