Verse Library verse

01 Snippet

Replaces long item or chat keywords with shorter abbreviations in strings, only when the input exceeds a specified length.

extracted-snippets/community/snippets/M8PE/fortnite-keyword-replacement/01-snippet.verse

# Source URL: https://dev.epicgames.com/community/snippets/M8PE/fortnite-keyword-replacement
# Local doc:  epic-docs/community/snippets/M8PE/fortnite-keyword-replacement.md
  # キーワード置換
  ReplaceKeyword(Input : string, Keywords : [string]string, ?MinLength : int = 20) : string =
  # 文字数がMinLength未満の場合はそのまま返す
  if (Input.Length < MinLength):
  return Input
  var Result : string = Input
  # キーワードが含まれている場合、置換
  for (Keyword -> ShortForm : Keywords):
  set Result = Result.ReplaceAll(Keyword, ShortForm)
  return Result

  Expand code  Copy full snippet(13 lines long)
* ```
  test():void=
      # キーワードマップを設定
      var Keywords : [string]string = map{}
      if:
          set Keywords["Shotgun"] = "SG"
          set Keywords["Assault Rifle"] = "AR"
          set Keywords["Submachine Gun"] = "SMG"
  
      # キーワードが含まれ、文字数超過しているので置換
      Print("{ReplaceKeyword("Enhanced Sentinel Pump Shotgun", Keywords)}")
      # Enhanced Sentinel Pump SG
  
      # キーワードが含まれ、文字数超過しているので置換
      Print("{ReplaceKeyword("Havoc Suppressed Assault Rifle", Keywords)}")
      # Havoc Suppressed AR

Sign in free to read the full source 🌴

This Verse Library file is members-only. Create a free account to view the complete source and download the .verse file.

Sign in with Discord

Comments

    Sign in to vote, comment, or suggest an edit. Sign in