Issunのブログ -3ページ目

Issunのブログ

Localization, VBA, and C#

Here is a super convenient function that will return the length of the longest string in a single cell. This is useful when you have to make sure none of the lines in a cell are over a character limit (just apply conditional formating to the cell with this formula so that it turns red if it goes over a specific limit, etc.).


I had originally written this so that is just looped over each character and checked if it was a line break or not, but that would make the function run slower the larger the cells became (it already runs really fast, though).


I recently discovered that spliting cell into an array of sentences (with line break being the divider) and then just using LEN on each of them was much faster, and handles well even with long text. The result is simple: check if there is a line break in the cell (if not just return LEN), then split the cell into sentences. Then run LEN on each sentence, setting the longest length you come across as the maxLength. At the end, you have the length of the longest sentence! Simple, huh?


-----------------------------------------

Function StrMax(ByVal text As String) As Long

Application.ScreenUpdating = False
Dim maxLength As Long
Dim i As Long
Dim strings() As String

If InStr(text, vbLf) <> 0 Then
strings() = Split(text, vbLf)
For i = 0 To UBound(strings())
If Len(strings(i)) > maxLength Then
maxLength = Len(strings(i))
End If
Next
StrMax = maxLength
Else
StrMax = Len(text)
End If

Application.ScreenUpdating = True

End Function


-----------------------------------------

I'm assuming most people know this, but you can enter a line break in excel search and replace by holding ALT and pressing 010.

Nothing will appear in the search box, but it's there. now try and replace with \n or something and see what happens!


iPhoneからの投稿
病院のトイレに

「みんなのトイレです。
きれいに使いましょう」

が書いてあった。駅でよく見る

「いつもキレイに使っていただき、
ありがとうございます」

より効果的だろう。グッド!



iPhoneからの投稿
This is a rather fun function I recently wrote in VBA for extracting text using regular expressions. Just write the regex pattern and for everything you want back, put it in parenthesis. The function just creates a new string of just the sub matches (items inside parenthesis).

So let's say you have a mojo limit that say blah blah ~15文字 and you just want all the numbers that appear before the 文字, you would write =RegexExtract(A1, "(\d+)文字") and it will extract the numerical data for you.

I've omitted error checking but it's something you could easily add.

------------------------------------------------------------------
Function RegexExtract(ByVal text As String, _
ByVal extract_what As String) As String

Application.ScreenUpdating = False
Dim i As Long
Dim result As String
Dim allMatches As Object
Dim RE As Object
Set RE = CreateObject("vbscript.regexp")

RE.Pattern = extract_what
RE.Global = True
Set allMatches = RE.Execute(text)

For i = 0 To allMatches.Item(0).submatches.count - 1
result = result & allMatches.Item(0).submatches.Item(i)
Next

RegexExtract = result
Application.ScreenUpdating = True

End Function
-----------------------------------------------------------------
Kanji Checker is a usefull tool for Japanese translators and editors when you want to limit the grade level of the kanji you are using, or want to scan over text you have to identify which kanji (and how many) might be outside your target grade level.

If you paste or type Japanese in the text box and either select a grade level from the pull down and hit check (or shortcut and right click the mouse over the box), it will scan the text for kanji outside the grade you specify. There is an optional name kanji box on the bottom if you wish to allow them.

By default it will change the color of illegal kanji red, but you can turn it off in the pull down options to get a speed boost, like if you are processing half a million moji or something.

The glyph report in the pull down menu is for developers. It outputs all the unique characters in the text, sorted by ascii code. Great for generating font sets.

The program is made so you can scan large quantities of text, so feel free to copy a column from excel and paste it right in the program and scan it.

Please try it out and leave any feedback you might have in the comments!
*Requires Microsoft .NET framework 4.1.

晴れLink:
http://uploading.com/files/1124ddm4/KC_v2.zip/


iPhoneからの投稿