12

While programming my Android app I just kept inserting elements in strings.xml with no order whatsoever. Is there a shortcut key (like Ctrl+Shift+F can organize android: attributes in an XML layout file) that sorts string elements alphabetically?

Chris Boyle
  • 11,423
  • 7
  • 48
  • 63
Akash
  • 367
  • 9
  • 21

3 Answers3

26

For anyone else who bumps into this. Copy all the string elements, paste into an Excel spreadsheet sort A-Z and then copy and paste back.

RobCroll
  • 2,571
  • 1
  • 26
  • 36
4

This is actually a feature in ADT plugin:

enter image description here

However, it only sort elements in Resources viewer, it doe not modify anything in the original strings.xml file.

yorkw
  • 40,926
  • 10
  • 117
  • 130
  • Its not exactly what I was looking for, but its a good help. thanks ;) Still if anyone knows how to organize the strings.xml alphabetically please leave an answer ;) – Akash Aug 14 '12 at 12:42
4

For those who have access to GNU or similar *nix command-line utils, you can do the following:

cat <(head -n 1 strings.xml) <(head strings.xml -n -2 | tail -n +2 | sort ) <(tail -n 2 strings.xml)

You may need to tweak the numbers slightly if your strings.xml has a larger XML header.

Steve Pomeroy
  • 10,071
  • 6
  • 34
  • 37