4. As shown in Figure 2, in $\triangle A B C$, $\angle B A C=$ $60^{\circ}, B C=18, D$ is a point on $A B$, $A C=B D, E$ is the midpoint of $C D$. Then the length of $A E$ is ( ).
(A) 12
(B) 9
(C) $9 \sqrt{3}$
(D) None of the above
4.B.

As shown in Figure 12, extend $AC$ to point $F$ such that $CF = AD$. Connect $BF$, and draw $CG \parallel AB$ intersecting $BF$ at point $G$. Connect $DG$ and $AG$.
Since $AC = DB$,
$$
CF = AD \text{, }
$$

Therefore, $AC + CF = DB + AD$, which means $AF = AB$.
Also, $\angle BAC = 60^{\circ}$, so $\triangle ABF$ is an equilateral triangle. Hence, $AF = BF$, and $\angle F = 60^{\circ}$.
Since $CG \parallel AB$, $\triangle CFG$ is also an equilateral triangle. Therefore, $CF = FG = CG$.
It is easy to see that $\triangle AGF \cong \triangle BCF$, so $AG = BC = 18$. Also, $CG \perp AD$, so quadrilateral $ACGD$ is a parallelogram. Therefore, $CD$ and $AG$ bisect each other, meaning $E$ is the midpoint of $AG$. Hence, $AE = \frac{1}{2} AG = \frac{1}{2} \times 18 = 9$.